From 5a6c1f262637af63d825dcad86d701dac58e0d31 Mon Sep 17 00:00:00 2001 From: Michal Piotrowski Date: Mon, 2 Nov 2015 21:50:41 +0100 Subject: [PATCH] asset test coverage --- .../Asset/Tests/Context/NullContextTest.php | 31 +++++++++ .../Tests/Context/RequestStackContextTest.php | 63 +++++++++++++++++++ .../EmptyVersionStrategyTest.php | 33 ++++++++++ 3 files changed, 127 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 0000000000..13e0e43d92 --- /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 0000000000..07f75c9f5b --- /dev/null +++ b/src/Symfony/Component/Asset/Tests/Context/RequestStackContextTest.php @@ -0,0 +1,63 @@ + + * + * 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 testGetBasePathEmpty() + { + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertEmpty($requestStackContext->getBasePath()); + } + + public function testGetBasePathSet() + { + $testBasePath = 'test-path'; + + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + $request->method('getBasePath') + ->willReturn($testBasePath); + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + $requestStack->method('getMasterRequest') + ->willReturn($request); + + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertEquals($testBasePath, $requestStackContext->getBasePath()); + } + + public function testIsSecureFalse() + { + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + $requestStackContext = new RequestStackContext($requestStack); + + $this->assertFalse($requestStackContext->isSecure()); + } + + public function testIsSecureTrue() + { + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + $request->method('isSecure') + ->willReturn(true); + $requestStack = $this->getMock('Symfony\Component\HttpFoundation\RequestStack'); + $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 0000000000..fb842dd4f7 --- /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)); + } +}