minor #16428 asset test coverage (eventhorizonpl)

This PR was submitted for the 2.8 branch but it was merged into the 2.7 branch instead (closes #16428).

Discussion
----------

asset test coverage

Hi,

This PR adds 100% tests code coverage for Asset component.

Best regards,
Michal

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| License       | MIT

Commits
-------

5a6c1f2 asset test coverage
This commit is contained in:
Fabien Potencier 2015-11-04 01:23:36 +01:00
commit e53b3b3a78
3 changed files with 127 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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());
}
}

View File

@ -0,0 +1,63 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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());
}
}

View File

@ -0,0 +1,33 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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));
}
}