Skip to content

Commit

Permalink
Added namespace to Extensions test
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHAnderson committed Oct 27, 2024
1 parent 58349d9 commit 1c3bfc2
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 65 deletions.
25 changes: 25 additions & 0 deletions tests/Assets/Extensions/ExtensionMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LaravelDoctrineTest\ORM\Assets\Extensions;

use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManagerInterface;
use LaravelDoctrine\ORM\Extensions\Extension;
use LaravelDoctrineTest\ORM\Feature\Extensions\ExtensionManagerTest;

class ExtensionMock implements Extension
{
public function addSubscribers(EventManager $manager, EntityManagerInterface $em): void
{
// Confirm it gets called
(new ExtensionManagerTest)->assertTrue(true);
}

/**
* @return mixed[]
*/
public function getFilters(): array
{
return [];
}
}
22 changes: 22 additions & 0 deletions tests/Assets/Extensions/ExtensionMock2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace LaravelDoctrineTest\ORM\Assets\Extensions;

use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManagerInterface;
use LaravelDoctrine\ORM\Extensions\Extension;

class ExtensionMock2 implements Extension
{
public function addSubscribers(EventManager $manager, EntityManagerInterface $em): void
{
}

/**
* @return mixed[]
*/
public function getFilters(): array
{
return [];
}
}
25 changes: 25 additions & 0 deletions tests/Assets/Extensions/ExtensionWithFiltersMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace LaravelDoctrineTest\ORM\Assets\Extensions;

use Doctrine\Common\EventManager;
use Doctrine\ORM\EntityManagerInterface;
use LaravelDoctrine\ORM\Extensions\Extension;

class ExtensionWithFiltersMock implements Extension
{
public function addSubscribers(EventManager $manager, EntityManagerInterface $em): void
{
}

/**
* @return mixed[]
*/
public function getFilters(): array
{
return [
'filter' => 'FilterMock',
'filter2' => 'FilterMock'
];
}
}
80 changes: 15 additions & 65 deletions tests/Feature/Extensions/ExtensionManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<?php

namespace LaravelDoctrineTest\ORM\Feature\Extensions;

use Doctrine\Common\EventManager;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\ORM\Query\FilterCollection;
use Doctrine\Persistence\ManagerRegistry;
use Illuminate\Contracts\Container\Container;
use LaravelDoctrine\ORM\Extensions\Extension;
use LaravelDoctrine\ORM\Extensions\ExtensionManager;
use LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock;
use LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock2;
use LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionWithFiltersMock;
use Mockery as m;
use Mockery\Mock;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -44,11 +49,6 @@ class ExtensionManagerTest extends TestCase
*/
protected $driver;

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

/**
* @var Container|Mock
*/
Expand All @@ -61,8 +61,7 @@ protected function setUp(): void
$this->em = m::mock(EntityManagerInterface::class);
$this->evm = m::mock(EventManager::class);
$this->configuration = m::mock(Configuration::class);
$this->driver = m::mock(\Doctrine\ORM\Mapping\Driver\XmlDriver::class);
$this->reader = m::mock(Reader::class);
$this->driver = m::mock(XmlDriver::class);

$this->manager = $this->newManager();
}
Expand Down Expand Up @@ -93,7 +92,7 @@ public function test_boot_manager_with_one_manager_and_one_extension()

// Should be inside booted extensions now
$booted = $this->manager->getBootedExtensions();
$this->assertTrue($booted['default']['ExtensionMock']);
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
}

public function test_boot_manager_with_two_managers_and_one_extension()
Expand All @@ -114,8 +113,8 @@ public function test_boot_manager_with_two_managers_and_one_extension()

// Should be inside booted extensions now
$booted = $this->manager->getBootedExtensions();
$this->assertTrue($booted['default']['ExtensionMock']);
$this->assertTrue($booted['custom']['ExtensionMock']);
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
$this->assertTrue((bool) $booted['custom']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
}

public function test_boot_manager_with_one_manager_and_two_extensions()
Expand All @@ -138,8 +137,8 @@ public function test_boot_manager_with_one_manager_and_two_extensions()

// Should be inside booted extensions now
$booted = $this->manager->getBootedExtensions();
$this->assertTrue($booted['default']['ExtensionMock']);
$this->assertTrue($booted['default']['ExtensionMock2']);
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock2']);
}

public function test_extension_will_only_be_booted_once()
Expand All @@ -161,7 +160,7 @@ public function test_extension_will_only_be_booted_once()

// Should be inside booted extensions now
$booted = $this->manager->getBootedExtensions();
$this->assertTrue($booted['default']['ExtensionMock']);
$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionMock']);
}

public function test_filters_get_registered_on_boot()
Expand Down Expand Up @@ -191,7 +190,8 @@ public function test_filters_get_registered_on_boot()

// Should be inside booted extensions now
$booted = $this->manager->getBootedExtensions();
$this->assertTrue($booted['default']['ExtensionWithFiltersMock']);

$this->assertTrue((bool) $booted['default']['LaravelDoctrineTest\ORM\Assets\Extensions\ExtensionWithFiltersMock']);
}

protected function tearDown(): void
Expand All @@ -206,53 +206,3 @@ protected function newManager()
return new ExtensionManager($this->container);
}
}

class ExtensionMock implements Extension
{
public function addSubscribers(EventManager $manager, EntityManagerInterface $em): void
{
// Confirm it get's called
(new ExtensionManagerTest)->assertTrue(true);
}

/**
* @return mixed[]
*/
public function getFilters(): array
{
return [];
}
}

class ExtensionMock2 implements Extension
{
public function addSubscribers(EventManager $manager, EntityManagerInterface $em): void
{
}

/**
* @return mixed[]
*/
public function getFilters(): array
{
return [];
}
}

class ExtensionWithFiltersMock implements Extension
{
public function addSubscribers(EventManager $manager, EntityManagerInterface $em): void
{
}

/**
* @return mixed[]
*/
public function getFilters(): array
{
return [
'filter' => 'FilterMock',
'filter2' => 'FilterMock'
];
}
}
2 changes: 2 additions & 0 deletions tests/Feature/Extensions/MappingDriverChainTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace LaravelDoctrineTest\ORM\Feature\Extensions;

use Doctrine\ORM\Mapping\Driver\SimplifiedXmlDriver;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\Persistence\Mapping\Driver\DefaultFileLocator;
Expand Down

0 comments on commit 1c3bfc2

Please sign in to comment.