|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Zenify\DoctrineFilters\Tests\FilterManager; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\DBAL\Connection; |
|
8
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
9
|
|
|
use Doctrine\ORM\EntityRepository; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use Zenify\DoctrineFilters\Contract\FilterManagerInterface; |
|
12
|
|
|
use Zenify\DoctrineFilters\FilterManager; |
|
13
|
|
|
use Zenify\DoctrineFilters\Tests\ContainerFactory; |
|
14
|
|
|
use Zenify\DoctrineFilters\Tests\Entity\Product; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
final class FilterManagerQueryTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var EntityManagerInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
private $entityManager; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var EntityRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
private $productRepository; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var FilterManagerInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $filterManager; |
|
34
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
protected function setUp() |
|
37
|
|
|
{ |
|
38
|
|
|
$container = (new ContainerFactory)->create(); |
|
39
|
|
|
$this->entityManager = $container->getByType(EntityManagerInterface::class); |
|
40
|
|
|
$this->filterManager = $container->getByType(FilterManager::class); |
|
41
|
|
|
$this->productRepository = $this->entityManager->getRepository(Product::class); |
|
42
|
|
|
|
|
43
|
|
|
$this->prepareDbData($container->getByType(Connection::class)); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function testFindOneBy() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->filterManager->enableFilters(); |
|
50
|
|
|
|
|
51
|
|
|
$product = $this->productRepository->findOneBy(['id' => 1]); |
|
52
|
|
|
$this->assertInstanceOf(Product::class, $product); |
|
53
|
|
|
$this->assertTrue($product->isActive()); |
|
54
|
|
|
|
|
55
|
|
|
$product2 = $this->productRepository->findOneBy(['id' => 2]); |
|
56
|
|
|
$this->assertNull($product2); |
|
57
|
|
|
|
|
58
|
|
|
// this should be NULL; this appears only in CLI |
|
59
|
|
|
$product2 = $this->productRepository->find(2); |
|
60
|
|
|
$this->assertInstanceOf(Product::class, $product2); |
|
61
|
|
|
$this->assertFalse($product2->isActive()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
private function prepareDbData(Connection $connection) |
|
66
|
|
|
{ |
|
67
|
|
|
$connection->query('CREATE TABLE product (id INTEGER NOT NULL, name string, is_active int NULL, PRIMARY KEY(id))'); |
|
68
|
|
|
|
|
69
|
|
|
$this->entityManager->persist(new Product(TRUE)); |
|
70
|
|
|
$this->entityManager->persist(new Product(FALSE)); |
|
71
|
|
|
$this->entityManager->flush(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: