Skip to content

Commit

Permalink
use the modern phpunit mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
dbu committed Jan 12, 2024
1 parent f157a0f commit 9813c8f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions Tests/LiipImagineBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Liip\ImagineBundle\DependencyInjection\LiipImagineExtension;
use Liip\ImagineBundle\LiipImagineBundle;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -49,7 +50,7 @@ public function testSubClassOfBundle(): void
public function testAddPasses(): void
{
$passes = [];
$containerMock = $this->createContainerBuilderMock();
$containerMock = $this->createMock(ContainerBuilder::class);
$containerMock
->expects($this->atLeastOnce())
->method('getExtension')
Expand All @@ -62,6 +63,10 @@ public function testAddPasses(): void

return true;
}));
$containerMock
->expects($this->exactly(3))
->method('registerForAutoconfiguration')
->willReturn($this->createMock(ChildDefinition::class));

$bundle = new LiipImagineBundle();
$bundle->build($containerMock);
Expand Down Expand Up @@ -95,12 +100,16 @@ public function testAddResolvers(): void
return true;
}));

$containerMock = $this->createContainerBuilderMock();
$containerMock = $this->createMock(ContainerBuilder::class);
$containerMock
->expects($this->atLeastOnce())
->method('getExtension')
->with('liip_imagine')
->willReturn($extensionMock);
$containerMock
->expects($this->exactly(3))
->method('registerForAutoconfiguration')
->willReturn($this->createMock(ChildDefinition::class));

$bundle = new LiipImagineBundle();
$bundle->build($containerMock);
Expand All @@ -123,12 +132,17 @@ public function testAddLoaders(): void

return true;
}));
$containerMock = $this->createContainerBuilderMock();
$containerMock = $this->createMock(ContainerBuilder::class);
$containerMock
->expects($this->atLeastOnce())
->method('getExtension')
->with('liip_imagine')
->willReturn($extensionMock);
$containerMock
->expects($this->exactly(3))
->method('registerForAutoconfiguration')
->willReturn($this->createMock(ChildDefinition::class));

$bundle = new LiipImagineBundle();
$bundle->build($containerMock);

Expand All @@ -140,18 +154,6 @@ public function testAddLoaders(): void
], $loaders);
}

/**
* @return MockObject|ContainerBuilder
*/
protected function createContainerBuilderMock()
{
return $this->createObjectMock(ContainerBuilder::class, [
'getExtension',
'addCompilerPass',
'registerForAutoconfiguration',
], false);
}

/**
* @return MockObject|LiipImagineExtension
*/
Expand Down

0 comments on commit 9813c8f

Please sign in to comment.