From fa43b7b9e4e56efada62f93e757bffb7f0c81f01 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 2 Nov 2015 21:50:41 +0100 Subject: [PATCH 1/4] asset test coverage p1 asset test coverage p2 asset test coverage p3 --- .../Asset/Tests/Context/NullContextTest.php | 31 ++++++++ .../Tests/Context/RequestStackContextTest.php | 72 +++++++++++++++++++ .../EmptyVersionStrategyTest.php | 33 +++++++++ 3 files changed, 136 insertions(+) create mode 100644 src/Symfony/Component/Asset/Tests/Context/NullContextTest.php create mode 100644 src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php create mode 100644 src/Symfony/Component/Asset/Tests/VersionStrategy/EmptyVersionStrategyTest.php diff --git a/src/Symfony/Component/Asset/Tests/Context/NullContextTest.php b/src/Symfony/Component/Asset/Tests/Context/NullContextTest.php new file mode 100644 index 0000000000000..13e0e43d92215 --- /dev/null +++ b/src/Symfony/Component/Asset/Tests/Context/NullContextTest.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Asset\Tests\Context; + +use Symfony\Component\Asset\Context\NullContext; + +class NullContextTest extends \PHPUnit_Framework_TestCase +{ + public function testGetBasePath() + { + $nullContext = new NullContext(); + + $this->assertEmpty($nullContext->getBasePath()); + } + + public function testIsSecure() + { + $nullContext = new NullContext(); + + $this->assertFalse($nullContext->isSecure()); + } +} diff --git a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php new file mode 100644 index 0000000000000..219bd5aec9e01 --- /dev/null +++ b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php @@ -0,0 +1,72 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Asset\Tests\Context; + +use Symfony\Component\Asset\Context\RequestStackContext; + +class RequestStackContextTest extends \PHPUnit_Framework_TestCase +{ + public function testConstructor() + { + $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') + ->getMock(); + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertInstanceOf('Symfony\Component\Asset\Context\RequestStackContext', $requestStackContext); + } + + public function testGetBasePath() + { + $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') + ->getMock(); + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertEmpty($requestStackContext->getBasePath()); + + $testBasePath = 'test-path'; + + $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') + ->getMock(); + $request->method('getBasePath') + ->willReturn($testBasePath); + $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') + ->getMock(); + $requestStack->method('getMasterRequest') + ->willReturn($request); + + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertEquals($testBasePath, $requestStackContext->getBasePath()); + } + + public function testIsSecure() + { + $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') + ->getMock(); + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertFalse($requestStackContext->isSecure()); + + $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') + ->getMock(); + $request->method('isSecure') + ->willReturn(true); + $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') + ->getMock(); + $requestStack->method('getMasterRequest') + ->willReturn($request); + + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertTrue($requestStackContext->isSecure()); + } +} diff --git a/src/Symfony/Component/Asset/Tests/VersionStrategy/EmptyVersionStrategyTest.php b/src/Symfony/Component/Asset/Tests/VersionStrategy/EmptyVersionStrategyTest.php new file mode 100644 index 0000000000000..fb842dd4f77a7 --- /dev/null +++ b/src/Symfony/Component/Asset/Tests/VersionStrategy/EmptyVersionStrategyTest.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Asset\Tests\VersionStrategy; + +use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy; + +class EmptyVersionStrategyTest extends \PHPUnit_Framework_TestCase +{ + public function testGetVersion() + { + $emptyVersionStrategy = new EmptyVersionStrategy(); + $path = 'test-path'; + + $this->assertEmpty($emptyVersionStrategy->getVersion($path)); + } + + public function testApplyVersion() + { + $emptyVersionStrategy = new EmptyVersionStrategy(); + $path = 'test-path'; + + $this->assertEquals($path, $emptyVersionStrategy->applyVersion($path)); + } +} From 642a5bf05d4cb1a8ae6f39c456e8f9ed80782d80 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 2 Nov 2015 23:23:21 +0100 Subject: [PATCH 2/4] address jakzal comments --- .../Component/Asset/Tests/Context/RequestStackContextTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php index 219bd5aec9e01..3383107d553d3 100644 --- a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php +++ b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php @@ -15,13 +15,13 @@ class RequestStackContextTest extends \PHPUnit_Framework_TestCase { - public function testConstructor() + public function testItIsAContext() { $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') ->getMock(); $requestStackContext = new RequestStackContext($requestStack); - $this->assertInstanceOf('Symfony\Component\Asset\Context\RequestStackContext', $requestStackContext); + $this->assertInstanceOf('Symfony\Component\Asset\Context\ContextInterface', $requestStackContext); } public function testGetBasePath() From 7382dc0ab994d750f18242c6d72fb75c2f27b904 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 2 Nov 2015 23:36:43 +0100 Subject: [PATCH 3/4] address jakzal comments p2 --- .../Tests/Context/RequestStackContextTest.php | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php index 3383107d553d3..1578b1f9a6e8c 100644 --- a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php +++ b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php @@ -24,22 +24,22 @@ public function testItIsAContext() $this->assertInstanceOf('Symfony\Component\Asset\Context\ContextInterface', $requestStackContext); } - public function testGetBasePath() + public function testGetBasePathEmpty() { - $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') - ->getMock(); + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); $requestStackContext = new RequestStackContext($requestStack); $this->assertEmpty($requestStackContext->getBasePath()); + } + public function testGetBasePathSet() + { $testBasePath = 'test-path'; - $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') - ->getMock(); + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); $request->method('getBasePath') ->willReturn($testBasePath); - $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') - ->getMock(); + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); $requestStack->method('getMasterRequest') ->willReturn($request); @@ -48,20 +48,20 @@ public function testGetBasePath() $this->assertEquals($testBasePath, $requestStackContext->getBasePath()); } - public function testIsSecure() + public function testIsSecureFalse() { - $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') - ->getMock(); + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); $requestStackContext = new RequestStackContext($requestStack); $this->assertFalse($requestStackContext->isSecure()); + } - $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') - ->getMock(); + public function testIsSecureTrue() + { + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); $request->method('isSecure') ->willReturn(true); - $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') - ->getMock(); + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); $requestStack->method('getMasterRequest') ->willReturn($request); From c19c90b5ec9f2008dd7f217dd51d622bef12a90d Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Tue, 3 Nov 2015 18:03:16 +0100 Subject: [PATCH 4/4] address stof comment --- .../Asset/Tests/Context/RequestStackContextTest.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php index 1578b1f9a6e8c..07f75c9f5b734 100644 --- a/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php +++ b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php @@ -15,15 +15,6 @@ class RequestStackContextTest extends \PHPUnit_Framework_TestCase { - public function testItIsAContext() - { - $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') - ->getMock(); - $requestStackContext = new RequestStackContext($requestStack); - - $this->assertInstanceOf('Symfony\Component\Asset\Context\ContextInterface', $requestStackContext); - } - public function testGetBasePathEmpty() { $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack');