Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Use createMock() and use import instead of FQCN
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
2 parents 7b0ff2c + f2204a5 commit 54a42aa
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
16 changes: 9 additions & 7 deletions Tests/Context/RequestStackContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\RequestStackContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;

class RequestStackContextTest extends TestCase
{
public function testGetBasePathEmpty()
{
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStackContext = new RequestStackContext($requestStack);

$this->assertEmpty($requestStackContext->getBasePath());
Expand All @@ -28,10 +30,10 @@ public function testGetBasePathSet()
{
$testBasePath = 'test-path';

$request = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class)->getMock();
$request = $this->createMock(Request::class);
$request->method('getBasePath')
->willReturn($testBasePath);
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStack->method('getMasterRequest')
->willReturn($request);

Expand All @@ -42,18 +44,18 @@ public function testGetBasePathSet()

public function testIsSecureFalse()
{
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStackContext = new RequestStackContext($requestStack);

$this->assertFalse($requestStackContext->isSecure());
}

public function testIsSecureTrue()
{
$request = $this->getMockBuilder(\Symfony\Component\HttpFoundation\Request::class)->getMock();
$request = $this->createMock(Request::class);
$request->method('isSecure')
->willReturn(true);
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStack->method('getMasterRequest')
->willReturn($request);

Expand All @@ -64,7 +66,7 @@ public function testIsSecureTrue()

public function testDefaultContext()
{
$requestStack = $this->getMockBuilder(\Symfony\Component\HttpFoundation\RequestStack::class)->getMock();
$requestStack = $this->createMock(RequestStack::class);
$requestStackContext = new RequestStackContext($requestStack, 'default-path', true);

$this->assertSame('default-path', $requestStackContext->getBasePath());
Expand Down
11 changes: 7 additions & 4 deletions Tests/PackagesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
namespace Symfony\Component\Asset\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Exception\InvalidArgumentException;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\PackageInterface;
use Symfony\Component\Asset\Packages;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;

Expand All @@ -21,8 +24,8 @@ class PackagesTest extends TestCase
public function testGetterSetters()
{
$packages = new Packages();
$packages->setDefaultPackage($default = $this->getMockBuilder(\Symfony\Component\Asset\PackageInterface::class)->getMock());
$packages->addPackage('a', $a = $this->getMockBuilder(\Symfony\Component\Asset\PackageInterface::class)->getMock());
$packages->setDefaultPackage($default = $this->createMock(PackageInterface::class));
$packages->addPackage('a', $a = $this->createMock(PackageInterface::class));

$this->assertSame($default, $packages->getPackage());
$this->assertSame($a, $packages->getPackage('a'));
Expand Down Expand Up @@ -57,14 +60,14 @@ public function testGetUrl()

public function testNoDefaultPackage()
{
$this->expectException(\Symfony\Component\Asset\Exception\LogicException::class);
$this->expectException(LogicException::class);
$packages = new Packages();
$packages->getPackage();
}

public function testUndefinedPackage()
{
$this->expectException(\Symfony\Component\Asset\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
$packages = new Packages();
$packages->getPackage('a');
}
Expand Down
6 changes: 4 additions & 2 deletions Tests/PathPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
namespace Symfony\Component\Asset\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;

class PathPackageTest extends TestCase
{
Expand Down Expand Up @@ -77,7 +79,7 @@ public function getContextConfigs()

public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder(\Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface::class)->getMock();
$versionStrategy = $this->createMock(VersionStrategyInterface::class);
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
Expand All @@ -88,7 +90,7 @@ public function testVersionStrategyGivesAbsoluteURL()

private function getContext($basePath)
{
$context = $this->getMockBuilder(\Symfony\Component\Asset\Context\ContextInterface::class)->getMock();
$context = $this->createMock(ContextInterface::class);
$context->expects($this->any())->method('getBasePath')->willReturn($basePath);

return $context;
Expand Down
12 changes: 8 additions & 4 deletions Tests/UrlPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
namespace Symfony\Component\Asset\Tests;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Asset\Context\ContextInterface;
use Symfony\Component\Asset\Exception\InvalidArgumentException;
use Symfony\Component\Asset\Exception\LogicException;
use Symfony\Component\Asset\UrlPackage;
use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;

class UrlPackageTest extends TestCase
{
Expand Down Expand Up @@ -86,7 +90,7 @@ public function getContextConfigs()

public function testVersionStrategyGivesAbsoluteURL()
{
$versionStrategy = $this->getMockBuilder(\Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface::class)->getMock();
$versionStrategy = $this->createMock(VersionStrategyInterface::class);
$versionStrategy->expects($this->any())
->method('applyVersion')
->willReturn('https://cdn.com/bar/main.css');
Expand All @@ -97,7 +101,7 @@ public function testVersionStrategyGivesAbsoluteURL()

public function testNoBaseUrls()
{
$this->expectException(\Symfony\Component\Asset\Exception\LogicException::class);
$this->expectException(LogicException::class);
new UrlPackage([], new EmptyVersionStrategy());
}

Expand All @@ -106,7 +110,7 @@ public function testNoBaseUrls()
*/
public function testWrongBaseUrl($baseUrls)
{
$this->expectException(\Symfony\Component\Asset\Exception\InvalidArgumentException::class);
$this->expectException(InvalidArgumentException::class);
new UrlPackage($baseUrls, new EmptyVersionStrategy());
}

Expand All @@ -120,7 +124,7 @@ public function getWrongBaseUrlConfig()

private function getContext($secure)
{
$context = $this->getMockBuilder(\Symfony\Component\Asset\Context\ContextInterface::class)->getMock();
$context = $this->createMock(ContextInterface::class);
$context->expects($this->any())->method('isSecure')->willReturn($secure);

return $context;
Expand Down

0 comments on commit 54a42aa

Please sign in to comment.