Skip to content

Commit

Permalink
minor #35793 Use strict assertSame instead of assertEquals in Asset c…
Browse files Browse the repository at this point in the history
…omponent tests (GromNaN)

This PR was merged into the 3.4 branch.

Discussion
----------

Use strict assertSame instead of assertEquals in Asset component tests

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | #35762 (comment)
| License       | MIT
| Doc PR        | N/A

Using `assertSame` instead of `assertEquals` is recommended when possible (see sebastianbergmann/phpunit-documentation-english#3). It is stricter and must be more efficient ([`===`](https://github.com/sebastianbergmann/phpunit/blob/8.5.2/src/Framework/Constraint/IsIdentical.php#L63) vs a [comparator class](https://github.com/sebastianbergmann/phpunit/blob/8.5.2/src/Framework/Constraint/IsEqual.php#L79)).

~~Also, removing useless string cast.~~

Commits
-------

e8f3e84 Use strict assertion in asset tests
  • Loading branch information
nicolas-grekas committed Feb 20, 2020
2 parents aa3637d + e8f3e84 commit 7b1e4ea
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testGetBasePathSet()

$requestStackContext = new RequestStackContext($requestStack);

$this->assertEquals($testBasePath, $requestStackContext->getBasePath());
$this->assertSame($testBasePath, $requestStackContext->getBasePath());
}

public function testIsSecureFalse()
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Asset/Tests/PackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PackageTest extends TestCase
public function testGetUrl($version, $format, $path, $expected)
{
$package = new Package($version ? new StaticVersionStrategy($version, $format) : new EmptyVersionStrategy());
$this->assertEquals($expected, $package->getUrl($path));
$this->assertSame($expected, $package->getUrl($path));
}

public function getConfigs()
Expand All @@ -50,6 +50,6 @@ public function getConfigs()
public function testGetVersion()
{
$package = new Package(new StaticVersionStrategy('v1'));
$this->assertEquals('v1', $package->getVersion('/foo'));
$this->assertSame('v1', $package->getVersion('/foo'));
}
}
16 changes: 8 additions & 8 deletions src/Symfony/Component/Asset/Tests/PackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ public function testGetterSetters()
$packages->setDefaultPackage($default = $this->getMockBuilder('Symfony\Component\Asset\PackageInterface')->getMock());
$packages->addPackage('a', $a = $this->getMockBuilder('Symfony\Component\Asset\PackageInterface')->getMock());

$this->assertEquals($default, $packages->getPackage());
$this->assertEquals($a, $packages->getPackage('a'));
$this->assertSame($default, $packages->getPackage());
$this->assertSame($a, $packages->getPackage('a'));

$packages = new Packages($default, ['a' => $a]);

$this->assertEquals($default, $packages->getPackage());
$this->assertEquals($a, $packages->getPackage('a'));
$this->assertSame($default, $packages->getPackage());
$this->assertSame($a, $packages->getPackage('a'));
}

public function testGetVersion()
Expand All @@ -40,8 +40,8 @@ public function testGetVersion()
['a' => new Package(new StaticVersionStrategy('a'))]
);

$this->assertEquals('default', $packages->getVersion('/foo'));
$this->assertEquals('a', $packages->getVersion('/foo', 'a'));
$this->assertSame('default', $packages->getVersion('/foo'));
$this->assertSame('a', $packages->getVersion('/foo', 'a'));
}

public function testGetUrl()
Expand All @@ -51,8 +51,8 @@ public function testGetUrl()
['a' => new Package(new StaticVersionStrategy('a'))]
);

$this->assertEquals('/foo?default', $packages->getUrl('/foo'));
$this->assertEquals('/foo?a', $packages->getUrl('/foo', 'a'));
$this->assertSame('/foo?default', $packages->getUrl('/foo'));
$this->assertSame('/foo?a', $packages->getUrl('/foo', 'a'));
}

public function testNoDefaultPackage()
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Asset/Tests/PathPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class PathPackageTest extends TestCase
public function testGetUrl($basePath, $format, $path, $expected)
{
$package = new PathPackage($basePath, new StaticVersionStrategy('v1', $format));
$this->assertEquals($expected, $package->getUrl($path));
$this->assertSame($expected, $package->getUrl($path));
}

public function getConfigs()
Expand Down Expand Up @@ -55,7 +55,7 @@ public function testGetUrlWithContext($basePathRequest, $basePath, $format, $pat
{
$package = new PathPackage($basePath, new StaticVersionStrategy('v1', $format), $this->getContext($basePathRequest));

$this->assertEquals($expected, $package->getUrl($path));
$this->assertSame($expected, $package->getUrl($path));
}

public function getContextConfigs()
Expand Down Expand Up @@ -83,7 +83,7 @@ public function testVersionStrategyGivesAbsoluteURL()
->willReturn('https://cdn.com/bar/main.css');
$package = new PathPackage('/subdirectory', $versionStrategy, $this->getContext('/bar'));

$this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
$this->assertSame('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
}

private function getContext($basePath)
Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/Asset/Tests/UrlPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class UrlPackageTest extends TestCase
public function testGetUrl($baseUrls, $format, $path, $expected)
{
$package = new UrlPackage($baseUrls, new StaticVersionStrategy('v1', $format));
$this->assertEquals($expected, $package->getUrl($path));
$this->assertSame($expected, $package->getUrl($path));
}

public function getConfigs()
Expand Down Expand Up @@ -58,7 +58,7 @@ public function testGetUrlWithContext($secure, $baseUrls, $format, $path, $expec
{
$package = new UrlPackage($baseUrls, new StaticVersionStrategy('v1', $format), $this->getContext($secure));

$this->assertEquals($expected, $package->getUrl($path));
$this->assertSame($expected, $package->getUrl($path));
}

public function getContextConfigs()
Expand All @@ -85,7 +85,7 @@ public function testVersionStrategyGivesAbsoluteURL()
->willReturn('https://cdn.com/bar/main.css');
$package = new UrlPackage('https://example.com', $versionStrategy);

$this->assertEquals('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
$this->assertSame('https://cdn.com/bar/main.css', $package->getUrl('main.css'));
}

public function testNoBaseUrls()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public function testApplyVersion()
$emptyVersionStrategy = new EmptyVersionStrategy();
$path = 'test-path';

$this->assertEquals($path, $emptyVersionStrategy->applyVersion($path));
$this->assertSame($path, $emptyVersionStrategy->applyVersion($path));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ public function testGetVersion()
{
$strategy = $this->createStrategy('manifest-valid.json');

$this->assertEquals('main.123abc.js', $strategy->getVersion('main.js'));
$this->assertSame('main.123abc.js', $strategy->getVersion('main.js'));
}

public function testApplyVersion()
{
$strategy = $this->createStrategy('manifest-valid.json');

$this->assertEquals('css/styles.555def.css', $strategy->getVersion('css/styles.css'));
$this->assertSame('css/styles.555def.css', $strategy->getVersion('css/styles.css'));
}

public function testApplyVersionWhenKeyDoesNotExistInManifest()
{
$strategy = $this->createStrategy('manifest-valid.json');

$this->assertEquals('css/other.css', $strategy->getVersion('css/other.css'));
$this->assertSame('css/other.css', $strategy->getVersion('css/other.css'));
}

public function testMissingManifestFileThrowsException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testGetVersion()
$version = 'v1';
$path = 'test-path';
$staticVersionStrategy = new StaticVersionStrategy($version);
$this->assertEquals($version, $staticVersionStrategy->getVersion($path));
$this->assertSame($version, $staticVersionStrategy->getVersion($path));
}

/**
Expand All @@ -31,7 +31,7 @@ public function testApplyVersion($path, $version, $format)
{
$staticVersionStrategy = new StaticVersionStrategy($version, $format);
$formatted = sprintf($format ?: '%s?%s', $path, $version);
$this->assertEquals($formatted, $staticVersionStrategy->applyVersion($path));
$this->assertSame($formatted, $staticVersionStrategy->applyVersion($path));
}

public function getConfigs()
Expand Down

0 comments on commit 7b1e4ea

Please sign in to comment.