Skip to content

Commit

Permalink
phpcs tests/Feature/Extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 28, 2024
1 parent abc4a6b commit 4e17f4e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 66 deletions.
87 changes: 34 additions & 53 deletions tests/Feature/Extensions/ExtensionManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaravelDoctrineTest\ORM\Feature\Extensions;

use Doctrine\Common\EventManager;
Expand All @@ -19,40 +21,19 @@

class ExtensionManagerTest extends TestCase
{
/**
* @var ManagerRegistry|Mock
*/
protected $registry;

/**
* @var ExtensionManager
*/
protected $manager;

/**
* @var Mock
*/
protected $em;

/**
* @var Mock
*/
protected $configuration;

/**
* @var Mock
*/
protected $evm;

/**
* @var Mock
*/
protected $driver;

/**
* @var Container|Mock
*/
protected $container;
protected ManagerRegistry|Mock $registry;

protected ExtensionManager $manager;

protected EntityManagerInterface $em;

protected Configuration $configuration;

protected EventManager $evm;

protected XmlDriver $driver;

protected Container|Mock $container;

protected function setUp(): void
{
Expand All @@ -68,26 +49,26 @@ protected function setUp(): void
parent::setUp();
}

public function test_register_extension()
public function testRegisterExtension(): void
{
$extension = new ExtensionMock;
$extension = new ExtensionMock();

$this->manager->register($extension);

$this->assertContains($extension, $this->manager->getExtensions());
}

public function test_boot_manager_with_one_manager_and_one_extension()
public function testBootManagerWithOneManagerAndOneExtension(): void
{
$this->registry->shouldReceive('getManagers')->andReturn([
'default' => $this->em
'default' => $this->em,
]);

$this->em->shouldReceive('getEventManager')->once()->andReturn($this->evm);
$this->em->shouldReceive('getConfiguration')->once()->andReturn($this->configuration);

// Register
$this->container->shouldReceive('make')->with(ExtensionMock::class)->once()->andReturn(new ExtensionMock);
$this->container->shouldReceive('make')->with(ExtensionMock::class)->once()->andReturn(new ExtensionMock());
$this->manager->register(ExtensionMock::class);

$this->manager->boot($this->registry);
Expand All @@ -97,18 +78,18 @@ public function test_boot_manager_with_one_manager_and_one_extension()
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
}

public function test_boot_manager_with_two_managers_and_one_extension()
public function testBootManagerWithTwoManagersAndOneExtension(): void
{
$this->registry->shouldReceive('getManagers')->andReturn([
'default' => $this->em,
'custom' => $this->em
'custom' => $this->em,
]);

$this->em->shouldReceive('getEventManager')->twice()->andReturn($this->evm);
$this->em->shouldReceive('getConfiguration')->twice()->andReturn($this->configuration);

// Register
$this->container->shouldReceive('make')->with(ExtensionMock::class)->twice()->andReturn(new ExtensionMock);
$this->container->shouldReceive('make')->with(ExtensionMock::class)->twice()->andReturn(new ExtensionMock());
$this->manager->register(ExtensionMock::class);

$this->manager->boot($this->registry);
Expand All @@ -119,20 +100,20 @@ public function test_boot_manager_with_two_managers_and_one_extension()
$this->assertTrue((bool) $booted['custom']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
}

public function test_boot_manager_with_one_manager_and_two_extensions()
public function testBootManagerWithOneManagerAndTwoExtensions(): void
{
$this->registry->shouldReceive('getManagers')->andReturn([
'default' => $this->em
'default' => $this->em,
]);

$this->em->shouldReceive('getEventManager')->twice()->andReturn($this->evm);
$this->em->shouldReceive('getConfiguration')->twice()->andReturn($this->configuration);

// Register
$this->container->shouldReceive('make')->with(ExtensionMock::class)->once()->andReturn(new ExtensionMock);
$this->container->shouldReceive('make')->with(ExtensionMock::class)->once()->andReturn(new ExtensionMock());
$this->manager->register(ExtensionMock::class);

$this->container->shouldReceive('make')->with(ExtensionMock2::class)->once()->andReturn(new ExtensionMock2);
$this->container->shouldReceive('make')->with(ExtensionMock2::class)->once()->andReturn(new ExtensionMock2());
$this->manager->register(ExtensionMock2::class);

$this->manager->boot($this->registry);
Expand All @@ -143,17 +124,17 @@ public function test_boot_manager_with_one_manager_and_two_extensions()
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock2']);
}

public function test_extension_will_only_be_booted_once()
public function testExtensionWillOnlyBeBootedOnce(): void
{
$this->registry->shouldReceive('getManagers')->andReturn([
'default' => $this->em
'default' => $this->em,
]);

$this->em->shouldReceive('getEventManager')->once()->andReturn($this->evm);
$this->em->shouldReceive('getConfiguration')->once()->andReturn($this->configuration);

// Register
$this->container->shouldReceive('make')->with(ExtensionMock::class)->times(3)->andReturn(new ExtensionMock);
$this->container->shouldReceive('make')->with(ExtensionMock::class)->times(3)->andReturn(new ExtensionMock());
$this->manager->register(ExtensionMock::class);
$this->manager->register(ExtensionMock::class);
$this->manager->register(ExtensionMock::class);
Expand All @@ -165,10 +146,10 @@ public function test_extension_will_only_be_booted_once()
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
}

public function test_filters_get_registered_on_boot()
public function testFiltersGetRegisteredOnBoot(): void
{
$this->registry->shouldReceive('getManagers')->andReturn([
'default' => $this->em
'default' => $this->em,
]);

$this->em->shouldReceive('getEventManager')->once()->andReturn($this->evm);
Expand All @@ -185,7 +166,7 @@ public function test_filters_get_registered_on_boot()
$collection->shouldReceive('enable')->once()->with('filter2');

// Register
$this->container->shouldReceive('make')->with(ExtensionWithFiltersMock::class)->once()->andReturn(new ExtensionWithFiltersMock);
$this->container->shouldReceive('make')->with(ExtensionWithFiltersMock::class)->once()->andReturn(new ExtensionWithFiltersMock());
$this->manager->register(ExtensionWithFiltersMock::class);

$this->manager->boot($this->registry);
Expand All @@ -205,7 +186,7 @@ protected function tearDown(): void
parent::tearDown();
}

protected function newManager()
protected function newManager(): ExtensionManager
{
return new ExtensionManager($this->container);
}
Expand Down
22 changes: 9 additions & 13 deletions tests/Feature/Extensions/MappingDriverChainTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace LaravelDoctrineTest\ORM\Feature\Extensions;

use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
Expand All @@ -16,15 +18,9 @@
*/
class MappingDriverChainTest extends TestCase
{
/**
* @var Mock
*/
protected $driver;
protected XmlDriver $driver;

/**
* @var MappingDriverChain
*/
protected $chain;
protected MappingDriverChain $chain;

protected function setUp(): void
{
Expand All @@ -34,12 +30,12 @@ protected function setUp(): void
parent::setUp();
}

public function test_get_default_driver()
public function testGetDefaultDriver(): void
{
$this->assertEquals($this->driver, $this->chain->getDefaultDriver());
}

public function test_can_add_paths()
public function testCanAddPaths(): void
{
$this->driver = m::mock(XmlDriver::class);
$this->chain = new MappingDriverChain($this->driver, 'Namespace');
Expand All @@ -53,7 +49,7 @@ public function test_can_add_paths()
$this->assertTrue(true);
}

public function test_can_add_paths_to_filedriver()
public function testCanAddPathsToFiledriver(): void
{
$driver = m::mock(XmlDriver::class);
$locator = m::mock(DefaultFileLocator::class);
Expand All @@ -68,7 +64,7 @@ public function test_can_add_paths_to_filedriver()
$this->assertTrue(true);
}

public function test_can_add_mappings_to_filedriver()
public function testCanAddMappingsToFiledriver(): void
{
$driver = m::mock(XmlDriver::class);
$locator = m::mock(DefaultFileLocator::class);
Expand All @@ -83,7 +79,7 @@ public function test_can_add_mappings_to_filedriver()
$this->assertTrue(true);
}

public function test_can_add_paths_to_simplified_filedriver()
public function testCanAddPathsToSimplifiedFiledriver(): void
{
$driver = m::mock(SimplifiedXmlDriver::class);
$locator = m::mock(SymfonyFileLocator::class);
Expand Down

0 comments on commit 4e17f4e

Please sign in to comment.