Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heredocs-related rules #4818

Merged
merged 2 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ public function testNoFormatterJSON()
$this->assertEquals('A Custom Reason', $this->response->getReason());
$this->assertEquals(201, $this->response->getStatusCode());

$expected = <<<EOH
{
"id": 3
}
EOH;
$expected = <<<'EOH'
{
"id": 3
}
EOH;
$this->assertEquals($expected, $this->response->getBody());
}

Expand All @@ -124,11 +124,11 @@ public function testAssociativeArrayPayload()
$this->formatter = null;
$controller = $this->makeController();
$payload = ['answer' => 42];
$expected = <<<EOH
{
"answer": 42
}
EOH;
$expected = <<<'EOH'
{
"answer": 42
}
EOH;
$controller->respond($payload);
$this->assertEquals($expected, $this->response->getBody());
}
Expand All @@ -142,13 +142,13 @@ public function testArrayPayload()
2,
3,
];
$expected = <<<EOH
[
1,
2,
3
]
EOH;
$expected = <<<'EOH'
[
1,
2,
3
]
EOH;
$controller->respond($payload);
$this->assertEquals($expected, $this->response->getBody());
}
Expand All @@ -160,12 +160,12 @@ public function testPHPtoArrayPayload()
$payload = new stdClass();
$payload->name = 'Tom';
$payload->id = 1;
$expected = <<<EOH
{
"name": "Tom",
"id": 1
}
EOH;
$expected = <<<'EOH'
{
"name": "Tom",
"id": 1
}
EOH;
$controller->respond((array) $payload);
$this->assertEquals($expected, $this->response->getBody());
}
Expand Down Expand Up @@ -479,11 +479,11 @@ public function testXMLFormatter()
$this->assertEquals('CodeIgniter\Format\XMLFormatter', get_class($this->formatter));

$controller->respondCreated(['id' => 3], 'A Custom Reason');
$expected = <<<EOH
<?xml version="1.0"?>
<response><id>3</id></response>
$expected = <<<'EOH'
<?xml version="1.0"?>
<response><id>3</id></response>

EOH;
EOH;
$this->assertEquals($expected, $this->response->getBody());
}

Expand Down
12 changes: 6 additions & 6 deletions tests/system/Database/Builder/DeleteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function testGetCompiledDelete()
$sql = $builder->getCompiledDelete();

$expectedSQL = <<<'EOL'
DELETE FROM "jobs"
WHERE "id" = 1
EOL;
DELETE FROM "jobs"
WHERE "id" = 1
EOL;
$this->assertSame($expectedSQL, $sql);
}

Expand All @@ -55,9 +55,9 @@ public function testGetCompiledDeleteWithLimit()
$sql = $builder->where('id', 1)->limit(10)->getCompiledDelete();

$expectedSQL = <<<'EOL'
DELETE FROM "jobs"
WHERE "id" = 1 LIMIT 10
EOL;
DELETE FROM "jobs"
WHERE "id" = 1 LIMIT 10
EOL;
$this->assertSame($expectedSQL, $sql);
}
}
36 changes: 18 additions & 18 deletions tests/system/Database/Builder/UpdateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,28 +120,28 @@ public function testUpdateBatch()
$space = ' ';

$expected = <<<EOF
UPDATE "jobs" SET "name" = CASE{$space}
WHEN "id" = :id: THEN :name:
WHEN "id" = :id.1: THEN :name.1:
ELSE "name" END, "description" = CASE{$space}
WHEN "id" = :id: THEN :description:
WHEN "id" = :id.1: THEN :description.1:
ELSE "description" END
WHERE "id" IN(:id:,:id.1:)
EOF;
UPDATE "jobs" SET "name" = CASE{$space}
WHEN "id" = :id: THEN :name:
WHEN "id" = :id.1: THEN :name.1:
ELSE "name" END, "description" = CASE{$space}
WHEN "id" = :id: THEN :description:
WHEN "id" = :id.1: THEN :description.1:
ELSE "description" END
WHERE "id" IN(:id:,:id.1:)
EOF;

$this->assertSame($expected, $query->getOriginalQuery());

$expected = <<<EOF
UPDATE "jobs" SET "name" = CASE{$space}
WHEN "id" = 2 THEN 'Comedian'
WHEN "id" = 3 THEN 'Cab Driver'
ELSE "name" END, "description" = CASE{$space}
WHEN "id" = 2 THEN 'There''s something in your teeth'
WHEN "id" = 3 THEN 'I am yellow'
ELSE "description" END
WHERE "id" IN(2,3)
EOF;
UPDATE "jobs" SET "name" = CASE{$space}
WHEN "id" = 2 THEN 'Comedian'
WHEN "id" = 3 THEN 'Cab Driver'
ELSE "name" END, "description" = CASE{$space}
WHEN "id" = 2 THEN 'There''s something in your teeth'
WHEN "id" = 3 THEN 'I am yellow'
ELSE "description" END
WHERE "id" IN(2,3)
EOF;

$this->assertSame($expected, $query->getQuery() );
}
Expand Down
120 changes: 60 additions & 60 deletions tests/system/Format/XMLFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public function testBasicXML()
'foo' => 'bar',
];

$expected = <<<EOH
<?xml version="1.0"?>
<response><foo>bar</foo></response>
$expected = <<<'EOH'
<?xml version="1.0"?>
<response><foo>bar</foo></response>

EOH;
EOH;

$this->assertEquals($expected, $this->xmlFormatter->format($data));
}
Expand All @@ -36,11 +36,11 @@ public function testFormatXMLWithMultilevelArray()
'foo' => ['bar'],
];

$expected = <<<EOH
<?xml version="1.0"?>
<response><foo><item0>bar</item0></foo></response>
$expected = <<<'EOH'
<?xml version="1.0"?>
<response><foo><item0>bar</item0></foo></response>

EOH;
EOH;

$this->assertEquals($expected, $this->xmlFormatter->format($data));
}
Expand All @@ -51,23 +51,23 @@ public function testFormatXMLWithMultilevelArrayAndNumericKey()
['foo'],
];

$expected = <<<EOH
<?xml version="1.0"?>
<response><item0><item0>foo</item0></item0></response>
$expected = <<<'EOH'
<?xml version="1.0"?>
<response><item0><item0>foo</item0></item0></response>

EOH;
EOH;

$this->assertEquals($expected, $this->xmlFormatter->format($data));
}

public function testStringFormatting()
{
$data = ['Something'];
$expected = <<<EOH
<?xml version="1.0"?>
<response><item0>Something</item0></response>
$expected = <<<'EOH'
<?xml version="1.0"?>
<response><item0>Something</item0></response>

EOH;
EOH;

$this->assertEquals($expected, $this->xmlFormatter->format($data));
}
Expand All @@ -78,11 +78,11 @@ public function testValidatingXmlTags()
'BBB096630BD' => 'foo',
'096630FR' => 'bar',
];
$expected = <<<EOH
<?xml version="1.0"?>
<response><BBB096630BD>foo</BBB096630BD><item096630FR>bar</item096630FR></response>
$expected = <<<'EOH'
<?xml version="1.0"?>
<response><BBB096630BD>foo</BBB096630BD><item096630FR>bar</item096630FR></response>

EOH;
EOH;

$this->assertEquals($expected, $this->xmlFormatter->format($data));
}
Expand All @@ -96,10 +96,10 @@ public function testValidatingXmlTags()
public function testValidatingInvalidTags(string $expected, array $input)
{
$expectedXML = <<<EOH
<?xml version="1.0"?>
<response><{$expected}>bar</{$expected}></response>
<?xml version="1.0"?>
<response><{$expected}>bar</{$expected}></response>

EOH;
EOH;

$this->assertEquals($expectedXML, $this->xmlFormatter->format($input));
}
Expand Down Expand Up @@ -171,43 +171,43 @@ public function testDeepNestedArrayToXml()
];

// do not change to tabs!!
$expectedXML = <<<EOF
<?xml version="1.0"?>
<response>
<data>
<master>
<name>Foo</name>
<email>[email protected]</email>
<dependents/>
</master>
<vote>
<list/>
</vote>
<user>
<account>
<demo>
<info>
<is_banned>true</is_banned>
<last_login>2020-08-31</last_login>
<last_login_ip>127.0.0.1</last_login_ip>
</info>
</demo>
</account>
</user>
<itemxml>
<itemxml_version>1.0</itemxml_version>
<itemxml_encoding>utf-8</itemxml_encoding>
</itemxml>
<item0>
<misc>miscellaneous</misc>
</item0>
<item1>
<misc_data>miscellaneous data</misc_data>
</item1>
</data>
</response>

EOF;
$expectedXML = <<<'EOF'
<?xml version="1.0"?>
<response>
<data>
<master>
<name>Foo</name>
<email>[email protected]</email>
<dependents/>
</master>
<vote>
<list/>
</vote>
<user>
<account>
<demo>
<info>
<is_banned>true</is_banned>
<last_login>2020-08-31</last_login>
<last_login_ip>127.0.0.1</last_login_ip>
</info>
</demo>
</account>
</user>
<itemxml>
<itemxml_version>1.0</itemxml_version>
<itemxml_encoding>utf-8</itemxml_encoding>
</itemxml>
<item0>
<misc>miscellaneous</misc>
</item0>
<item1>
<misc_data>miscellaneous data</misc_data>
</item1>
</data>
</response>

EOF;

$dom = new DOMDocument('1.0');
$dom->preserveWhiteSpace = false;
Expand Down
Loading