Skip to content

Commit

Permalink
Merge 4d7378e into 34546e2
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Jul 31, 2019
2 parents 34546e2 + 4d7378e commit e8e1996
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 21 deletions.
6 changes: 6 additions & 0 deletions phpstan.neon
Expand Up @@ -11,5 +11,11 @@ parameters:

# Symfony DI
- '#Cannot call method end\(\) on Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface\|null.#'
- "/Call to function method_exists.. with 'Symfony.+' and 'getRootNode' will always evaluate to false./"

# PHPUnit
-
message: '#Property .*::\$.* has no typehint specified.#'
path: tests/

- '#Core23\\Doctrine\\Tests\\Fixtures\\DemoEntityManager::__construct\(\) does not call parent constructor from Sonata\\Doctrine\\Model\\BaseManager.#'
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/DependencyInjection/Configuration.php
Expand Up @@ -22,7 +22,7 @@ public function getConfigTreeBuilder()
$treeBuilder = new TreeBuilder('core23_doctrine');

// Keep compatibility with symfony/config < 4.2
if (!method_exists($treeBuilder, 'getRootNode')) {
if (!method_exists(TreeBuilder::class, 'getRootNode')) {
$rootNode = $treeBuilder->root('core23_doctrine');
} else {
$rootNode = $treeBuilder->getRootNode();
Expand Down
7 changes: 5 additions & 2 deletions src/Test/ORM/EntityManagerMockFactory.php
Expand Up @@ -28,7 +28,7 @@ final class EntityManagerMockFactory
*
* @return EntityManager|MockObject
*/
public static function create(TestCase $test, Closure $qbCallback, $fields): MockObject
public static function create(TestCase $test, Closure $qbCallback, array $fields): MockObject
{
$qb = $test->getMockBuilder(QueryBuilder::class)->disableOriginalConstructor()->getMock();

Expand Down Expand Up @@ -65,7 +65,10 @@ private static function prepareQueryBuilder(TestCase $test, MockObject $qb): voi
$qb->method('leftJoin')->willReturn($qb);
}

private static function prepareMetadata(TestCase $test, $fields): MockObject
/**
* @param string[] $fields
*/
private static function prepareMetadata(TestCase $test, array $fields): MockObject
{
$metadata = $test->getMockBuilder(ClassMetadataInfo::class)->disableOriginalConstructor()->getMock();
$metadata->method('getFieldNames')->willReturn($fields);
Expand Down
8 changes: 0 additions & 8 deletions tests/Bridge/Symfony/Bundle/Core23DoctrineBundleTest.php
Expand Up @@ -12,17 +12,9 @@
use Core23\Doctrine\Bridge\Symfony\Bundle\Core23DoctrineBundle;
use Core23\Doctrine\Bridge\Symfony\DependencyInjection\Core23DoctrineExtension;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

final class Core23DoctrineBundleTest extends TestCase
{
public function testItIsInstantiable(): void
{
$bundle = new Core23DoctrineBundle();

static::assertInstanceOf(BundleInterface::class, $bundle);
}

public function testGetPath(): void
{
$bundle = new Core23DoctrineBundle();
Expand Down
Expand Up @@ -12,6 +12,12 @@
namespace Core23\Doctrine\Tests\Bridge\Symfony\DependencyInjection;

use Core23\Doctrine\Bridge\Symfony\DependencyInjection\Core23DoctrineExtension;
use Core23\Doctrine\EventListener\ORM\ConfirmableListener;
use Core23\Doctrine\EventListener\ORM\DeletableListener;
use Core23\Doctrine\EventListener\ORM\LifecycleDateListener;
use Core23\Doctrine\EventListener\ORM\SortableListener;
use Core23\Doctrine\EventListener\ORM\TablePrefixEventListener;
use Core23\Doctrine\EventListener\ORM\UniqueActiveListener;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;

final class Core23DoctrineExtensionTest extends AbstractExtensionTestCase
Expand All @@ -20,7 +26,12 @@ public function testLoadDefault(): void
{
$this->load();

static::assertTrue(true);
$this->assertContainerBuilderHasService(ConfirmableListener::class);
$this->assertContainerBuilderHasService(DeletableListener::class);
$this->assertContainerBuilderHasService(LifecycleDateListener::class);
$this->assertContainerBuilderHasService(SortableListener::class);
$this->assertContainerBuilderHasService(UniqueActiveListener::class);
$this->assertContainerBuilderHasService(TablePrefixEventListener::class);
}

protected function getContainerExtensions()
Expand Down
15 changes: 13 additions & 2 deletions tests/EventListener/ORM/LifecycleDateListenerTest.php
Expand Up @@ -15,6 +15,7 @@
use Core23\Doctrine\Tests\Fixtures\EmptyClass;
use DateTime;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Events;
Expand Down Expand Up @@ -68,15 +69,20 @@ public function testPrePersistForInvalidClass(): void
{
$object = $this->prophesize(stdClass::class);

$entityManager = $this->prophesize(EntityManagerInterface::class);

$eventArgs = $this->prophesize(LifecycleEventArgs::class);
$eventArgs->getObject()
->willReturn($object)
;
$eventArgs->getEntityManager()
->willReturn($entityManager)
;

$listener = new LifecycleDateListener();
$listener->prePersist($eventArgs->reveal());

static::assertTrue(true);
$entityManager->createQueryBuilder()->shouldNotHaveBeenCalled();
}

public function testPreUpdate(): void
Expand All @@ -99,15 +105,20 @@ public function testPreUpdateForInvalidClass(): void
{
$object = $this->prophesize(stdClass::class);

$entityManager = $this->prophesize(EntityManagerInterface::class);

$eventArgs = $this->prophesize(LifecycleEventArgs::class);
$eventArgs->getObject()
->willReturn($object)
;
$eventArgs->getEntityManager()
->willReturn($entityManager)
;

$listener = new LifecycleDateListener();
$listener->preUpdate($eventArgs->reveal());

static::assertTrue(true);
$entityManager->createQueryBuilder()->shouldNotHaveBeenCalled();
}

public function testLoadClassMetadataWithNoValidData(): void
Expand Down
15 changes: 13 additions & 2 deletions tests/EventListener/ORM/SortableListenerTest.php
Expand Up @@ -13,6 +13,7 @@
use Core23\Doctrine\Tests\Fixtures\ClassWithAllProperties;
use Core23\Doctrine\Tests\Fixtures\EmptyClass;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
Expand Down Expand Up @@ -49,30 +50,40 @@ public function testPrePersistForInvalidClass(): void
{
$object = $this->prophesize(stdClass::class);

$entityManager = $this->prophesize(EntityManagerInterface::class);

$eventArgs = $this->prophesize(PreUpdateEventArgs::class);
$eventArgs->getEntity()
->willReturn($object)
;
$eventArgs->getEntityManager()
->willReturn($entityManager)
;

$listener = new SortableListener();
$listener->prePersist($eventArgs->reveal());

static::assertTrue(true);
$entityManager->createQueryBuilder()->shouldNotHaveBeenCalled();
}

public function testPreRemoveForInvalidClass(): void
{
$object = $this->prophesize(stdClass::class);

$entityManager = $this->prophesize(EntityManagerInterface::class);

$eventArgs = $this->prophesize(LifecycleEventArgs::class);
$eventArgs->getEntity()
->willReturn($object)
;
$eventArgs->getEntityManager()
->willReturn($entityManager)
;

$listener = new SortableListener();
$listener->preRemove($eventArgs->reveal());

static::assertTrue(true);
$entityManager->createQueryBuilder()->shouldNotHaveBeenCalled();
}

public function testLoadClassMetadataWithNoValidData(): void
Expand Down
15 changes: 13 additions & 2 deletions tests/EventListener/ORM/UniqueActiveListenerTest.php
Expand Up @@ -13,6 +13,7 @@
use Core23\Doctrine\Tests\Fixtures\ClassWithAllProperties;
use Core23\Doctrine\Tests\Fixtures\EmptyClass;
use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Event\PreUpdateEventArgs;
Expand Down Expand Up @@ -48,30 +49,40 @@ public function testPrePersistForInvalidClass(): void
{
$object = $this->prophesize(stdClass::class);

$entityManager = $this->prophesize(EntityManagerInterface::class);

$eventArgs = $this->prophesize(PreUpdateEventArgs::class);
$eventArgs->getEntity()
->willReturn($object)
;
$eventArgs->getEntityManager()
->willReturn($entityManager)
;

$listener = new UniqueActiveListener();
$listener->prePersist($eventArgs->reveal());

static::assertTrue(true);
$entityManager->createQueryBuilder()->shouldNotHaveBeenCalled();
}

public function testPreUpdateForInvalidClass(): void
{
$object = $this->prophesize(stdClass::class);

$entityManager = $this->prophesize(EntityManagerInterface::class);

$eventArgs = $this->prophesize(LifecycleEventArgs::class);
$eventArgs->getEntity()
->willReturn($object)
;
$eventArgs->getEntityManager()
->willReturn($entityManager)
;

$listener = new UniqueActiveListener();
$listener->preUpdate($eventArgs->reveal());

static::assertTrue(true);
$entityManager->createQueryBuilder()->shouldNotHaveBeenCalled();
}

public function testLoadClassMetadataWithNoValidData(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Manager/ORM/BaseQueryTraitTest.php
Expand Up @@ -18,7 +18,7 @@ final class BaseQueryTraitTest extends TestCase
{
private $manager;

protected function setUp()
protected function setUp(): void
{
$repository = $this->prophesize(EntityRepository::class);

Expand Down
2 changes: 1 addition & 1 deletion tests/Manager/ORM/SearchQueryTraitTest.php
Expand Up @@ -20,7 +20,7 @@ final class SearchQueryTraitTest extends TestCase
{
private $manager;

protected function setUp()
protected function setUp(): void
{
$repository = $this->prophesize(EntityRepository::class);

Expand Down
5 changes: 4 additions & 1 deletion vendor-bin/phpstan/composer.json
@@ -1,10 +1,13 @@
{
"require": {
"ekino/phpstan-banned-code": "^0.1",
"jangregor/phpstan-prophecy": "^0.4",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-doctrine": "^0.11",
"phpstan/phpstan-phpunit": "^0.11"
"phpstan/phpstan-phpunit": "^0.11",
"phpstan/phpstan-strict-rules": "^0.11",
"phpstan/phpstan-symfony": "^0.11"
},
"conflict": {
"phpunit/phpunit": ">=8.0"
Expand Down

0 comments on commit e8e1996

Please sign in to comment.