-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
asset test coverage #16428
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
asset test coverage #16428
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
asset test coverage p2 asset test coverage p3
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| <?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 testConstructor() | ||
| { | ||
| $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') | ||
| ->getMock(); | ||
| $requestStackContext = new RequestStackContext($requestStack); | ||
|
|
||
| $this->assertInstanceOf('Symfony\Component\Asset\Context\RequestStackContext', $requestStackContext); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is not really useful as all it does is it verifies if PHP works properly. All the other tests already cover this case. I'd see some value in such a test case if it was verifying if a certain interface is implemented (it would communicate certain design decision). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something like that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes 👍 I wouldn't call the method |
||
| } | ||
|
|
||
| public function testGetBasePath() | ||
| { | ||
| $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') | ||
| ->getMock(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could simply be |
||
| $requestStackContext = new RequestStackContext($requestStack); | ||
|
|
||
| $this->assertEmpty($requestStackContext->getBasePath()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be the end of the test case. As a rule of thumb it's good to follow an arrange-act-assert flow (for readability and maintainability). I know there's lots of tests violating this rule in Symfony, but I'd rather don't add more of them. This also shows a problem with naming test cases after a method being tested, as it basically forces you to put everything in a single method. I prefer to summarise the requirement/rule (for example: testItIsInitialisedWithAnEmptyBasePath, testItRetrievesTheBasePathFromTheMasterRequest). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how about testGetBasePathEmpty + testGetBasePathSet and testIsSecureFalse + testIsSecureTrue? a bit shorter method names. |
||
|
|
||
| $testBasePath = 'test-path'; | ||
|
|
||
| $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') | ||
| ->getMock(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $request->method('getBasePath') | ||
| ->willReturn($testBasePath); | ||
| $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack') | ||
| ->getMock(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $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(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| $requestStackContext = new RequestStackContext($requestStack); | ||
|
|
||
| $this->assertFalse($requestStackContext->isSecure()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this should be the end of the test case. Following code is a separate one. |
||
|
|
||
| $request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request') | ||
| ->getMock(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed B5FA to describe this comment to others. Learn more.
|
||
| $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()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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)); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last occurrence of the mock builder :)