Passed
Pull Request — master (#126)
by David
05:55
created

testFindFromRawSqlWithDistinctQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
/*
5
 Copyright (C) 2006-2018 David Négrier - THE CODING MACHINE
6
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
*/
21
22
namespace TheCodingMachine\TDBM;
23
24
use Doctrine\Common\Cache\ArrayCache;
25
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
26
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
27
use Mouf\Database\SchemaAnalyzer\SchemaAnalyzer;
28
use Ramsey\Uuid\Uuid;
29
use ReflectionClass;
30
use ReflectionMethod;
31
use TheCodingMachine\TDBM\Dao\TestArticleDao;
32
use TheCodingMachine\TDBM\Dao\TestCountryDao;
33
use TheCodingMachine\TDBM\Dao\TestRoleDao;
34
use TheCodingMachine\TDBM\Dao\TestUserDao;
35
use TheCodingMachine\TDBM\Fixtures\Interfaces\TestUserDaoInterface;
36
use TheCodingMachine\TDBM\Fixtures\Interfaces\TestUserInterface;
37
use TheCodingMachine\TDBM\Test\Dao\AllNullableDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\AllNullableDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use TheCodingMachine\TDBM\Test\Dao\AnimalDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\AnimalDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use TheCodingMachine\TDBM\Test\Dao\ArtistDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\ArtistDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
use TheCodingMachine\TDBM\Test\Dao\Bean\AllNullableBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...ao\Bean\AllNullableBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
use TheCodingMachine\TDBM\Test\Dao\Bean\AnimalBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\AnimalBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
42
use TheCodingMachine\TDBM\Test\Dao\Bean\ArrayBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\ArrayBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
use TheCodingMachine\TDBM\Test\Dao\Bean\Article2Bean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\Article2Bean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
use TheCodingMachine\TDBM\Test\Dao\Bean\ArticleBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\ArticleBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
45
use TheCodingMachine\TDBM\Test\Dao\Bean\BoatBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\BoatBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
46
use TheCodingMachine\TDBM\Test\Dao\Bean\CatBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\CatBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
47
use TheCodingMachine\TDBM\Test\Dao\Bean\CategoryBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\CategoryBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
48
use TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\CountryBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
49
use TheCodingMachine\TDBM\Test\Dao\Bean\DateArrayBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\DateArrayBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
use TheCodingMachine\TDBM\Test\Dao\Bean\DogBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\DogBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
51
use TheCodingMachine\TDBM\Test\Dao\Bean\FileBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\FileBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
52
use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\ArticleBaseBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...nerated\ArticleBaseBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
53
use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\BoatBaseBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...\Generated\BoatBaseBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
54
use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\FileBaseBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...\Generated\FileBaseBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
use TheCodingMachine\TDBM\Test\Dao\Bean\Generated\UserBaseBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...\Generated\UserBaseBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
use TheCodingMachine\TDBM\Test\Dao\Bean\NodeBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\NodeBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
57
use TheCodingMachine\TDBM\Test\Dao\Bean\PersonBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\PersonBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
58
use TheCodingMachine\TDBM\Test\Dao\Bean\RefNoPrimKeyBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...o\Bean\RefNoPrimKeyBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
59
use TheCodingMachine\TDBM\Test\Dao\Bean\RoleBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\RoleBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
60
use TheCodingMachine\TDBM\Test\Dao\Bean\StateBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\StateBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
61
use TheCodingMachine\TDBM\Test\Dao\Bean\UserBean;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\Bean\UserBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
62
use TheCodingMachine\TDBM\Test\Dao\BoatDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\BoatDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
63
use TheCodingMachine\TDBM\Test\Dao\CatDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\CatDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
64
use TheCodingMachine\TDBM\Test\Dao\CategoryDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\CategoryDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
65
use TheCodingMachine\TDBM\Test\Dao\ContactDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\ContactDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
66
use TheCodingMachine\TDBM\Test\Dao\CountryDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\CountryDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
use TheCodingMachine\TDBM\Test\Dao\DogDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\DogDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
68
use TheCodingMachine\TDBM\Test\Dao\FileDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\FileDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
69
use TheCodingMachine\TDBM\Test\Dao\Generated\ContactBaseDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...enerated\ContactBaseDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
70
use TheCodingMachine\TDBM\Test\Dao\Generated\UserBaseDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Te...o\Generated\UserBaseDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
71
use TheCodingMachine\TDBM\Test\Dao\NodeDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\NodeDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
72
use TheCodingMachine\TDBM\Test\Dao\RefNoPrimKeyDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\RefNoPrimKeyDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
73
use TheCodingMachine\TDBM\Test\Dao\RoleDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\RoleDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
use TheCodingMachine\TDBM\Test\Dao\StateDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\StateDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
75
use TheCodingMachine\TDBM\Test\Dao\UserDao;
0 ignored issues
show
Bug introduced by
The type TheCodingMachine\TDBM\Test\Dao\UserDao was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
76
use TheCodingMachine\TDBM\Utils\PathFinder\NoPathFoundException;
77
use TheCodingMachine\TDBM\Utils\PathFinder\PathFinder;
78
use TheCodingMachine\TDBM\Utils\TDBMDaoGenerator;
79
use Symfony\Component\Process\Process;
80
81
class TDBMDaoGeneratorTest extends TDBMAbstractServiceTest
82
{
83
    /** @var TDBMDaoGenerator $tdbmDaoGenerator */
84
    protected $tdbmDaoGenerator;
85
86
    private $rootPath;
87
88
    protected function setUp()
89
    {
90
        parent::setUp();
91
        $schemaManager = $this->tdbmService->getConnection()->getSchemaManager();
92
        $schemaAnalyzer = new SchemaAnalyzer($schemaManager);
93
        $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer($this->tdbmService->getConnection(), new ArrayCache(), $schemaAnalyzer);
94
        $this->tdbmDaoGenerator = new TDBMDaoGenerator($this->getConfiguration(), $tdbmSchemaAnalyzer);
95
        $this->rootPath = __DIR__ . '/../';
96
        //$this->tdbmDaoGenerator->setComposerFile($this->rootPath.'composer.json');
97
    }
98
99
    public function testDaoGeneration()
100
    {
101
        // Remove all previously generated files.
102
        $this->recursiveDelete($this->rootPath . 'src/Test/Dao/');
103
        mkdir($this->rootPath . 'src/Test/Dao/Generated', 0755, true);
104
        // Let's generate a dummy file to see it is indeed removed.
105
        $dummyFile = $this->rootPath . 'src/Test/Dao/Generated/foobar.php';
106
        touch($dummyFile);
107
        $this->assertFileExists($dummyFile);
108
109
        $this->tdbmDaoGenerator->generateAllDaosAndBeans();
110
111
        $this->assertFileNotExists($dummyFile);
112
113
        // Let's require all files to check they are valid PHP!
114
        // Test the daoFactory
115
        require_once $this->rootPath . 'src/Test/Dao/Generated/DaoFactory.php';
116
        // Test the others
117
118
        $beanDescriptors = $this->getDummyGeneratorListener()->getBeanDescriptors();
119
120
        foreach ($beanDescriptors as $beanDescriptor) {
121
            $daoName = $beanDescriptor->getDaoClassName();
122
            $daoBaseName = $beanDescriptor->getBaseDaoClassName();
123
            $beanName = $beanDescriptor->getBeanClassName();
124
            $baseBeanName = $beanDescriptor->getBaseBeanClassName();
125
            require_once $this->rootPath . 'src/Test/Dao/Bean/Generated/' . $baseBeanName . '.php';
126
            require_once $this->rootPath . 'src/Test/Dao/Bean/' . $beanName . '.php';
127
            require_once $this->rootPath . 'src/Test/Dao/Generated/' . $daoBaseName . '.php';
128
            require_once $this->rootPath . 'src/Test/Dao/' . $daoName . '.php';
129
        }
130
131
        // Check that pivot tables do not generate DAOs or beans.
132
        $this->assertFalse(class_exists('TheCodingMachine\\TDBM\\Test\\Dao\\RolesRightDao'));
133
    }
134
135
    public function testGenerationException()
136
    {
137
        $configuration = new Configuration('UnknownVendor\\Dao', 'UnknownVendor\\Bean', self::getConnection(), $this->getNamingStrategy());
138
139
        $schemaManager = $this->tdbmService->getConnection()->getSchemaManager();
140
        $schemaAnalyzer = new SchemaAnalyzer($schemaManager);
141
        $tdbmSchemaAnalyzer = new TDBMSchemaAnalyzer($this->tdbmService->getConnection(), new ArrayCache(), $schemaAnalyzer);
142
        $tdbmDaoGenerator = new TDBMDaoGenerator($configuration, $tdbmSchemaAnalyzer);
143
        $this->rootPath = __DIR__ . '/../../../../';
144
        //$tdbmDaoGenerator->setComposerFile($this->rootPath.'composer.json');
145
146
        $this->expectException(NoPathFoundException::class);
147
        $tdbmDaoGenerator->generateAllDaosAndBeans();
148
    }
149
150
    /**
151
     * Delete a file or recursively delete a directory.
152
     *
153
     * @param string $str Path to file or directory
154
     * @return bool
155
     */
156
    private function recursiveDelete(string $str): bool
157
    {
158
        if (is_file($str)) {
159
            return @unlink($str);
160
        } elseif (is_dir($str)) {
161
            $scan = glob(rtrim($str, '/') . '/*');
162
            foreach ($scan as $index => $path) {
163
                $this->recursiveDelete($path);
164
            }
165
166
            return @rmdir($str);
167
        }
168
        return false;
169
    }
170
171
    /**
172
     * @depends testDaoGeneration
173
     */
174
    public function testGetBeanClassName()
175
    {
176
        $this->assertEquals(UserBean::class, $this->tdbmService->getBeanClassName('users'));
177
178
        // Let's create another TDBMService to test the cache.
179
        $configuration = new Configuration('TheCodingMachine\\TDBM\\Test\\Dao\\Bean', 'TheCodingMachine\\TDBM\\Test\\Dao', self::getConnection(), $this->getNamingStrategy(), $this->getCache(), null, null, [$this->getDummyGeneratorListener()]);
180
        $configuration->setPathFinder(new PathFinder(null, dirname(__DIR__, 4)));
181
        $newTdbmService = new TDBMService($configuration);
182
        $this->assertEquals(UserBean::class, $newTdbmService->getBeanClassName('users'));
183
    }
184
185
    /**
186
     * @depends testDaoGeneration
187
     */
188
    public function testGeneratedGetById()
189
    {
190
        $contactDao = new ContactDao($this->tdbmService);
191
        $contactBean = $contactDao->getById(1);
192
        $this->assertEquals(1, $contactBean->getId());
193
        $this->assertInstanceOf('\\DateTimeInterface', $contactBean->getCreatedAt());
194
195
        // FIXME: Question: que faire du paramètre stockage "UTC"????
196
    }
197
198
    /**
199
     * @depends testDaoGeneration
200
     */
201
    public function testGeneratedGetByIdLazyLoaded()
202
    {
203
        $roleDao = new RoleDao($this->tdbmService);
204
        $roleBean = $roleDao->getById(1, true);
205
        $this->assertEquals(1, $roleBean->getId());
206
        $this->assertInstanceOf('\\DateTimeInterface', $roleBean->getCreatedAt());
207
208
        $roleBean2 = $roleDao->getById(1, true);
209
        $this->assertTrue($roleBean === $roleBean2);
210
    }
211
212
    /**
213
     * @depends testDaoGeneration
214
     */
215
    public function testDefaultValueOnNewBean()
216
    {
217
        $roleBean = new RoleBean('my_role');
218
        $this->assertEquals(1, $roleBean->getStatus());
219
    }
220
221
    /**
222
     * @depends testDaoGeneration
223
     */
224
    public function testForeignKeyInBean()
225
    {
226
        $userDao = new UserDao($this->tdbmService);
227
        $userBean = $userDao->getById(1);
228
        $country = $userBean->getCountry();
229
230
        $this->assertEquals('UK', $country->getLabel());
231
232
        $userBean2 = $userDao->getById(1);
233
        $this->assertTrue($userBean === $userBean2);
234
235
        $contactDao = new ContactDao($this->tdbmService);
236
        $contactBean = $contactDao->getById(1);
237
238
        $this->assertTrue($userBean === $contactBean);
239
    }
240
241
    /**
242
     * @depends testDaoGeneration
243
     */
244
    public function testNewBeans()
245
    {
246
        $countryDao = new CountryDao($this->tdbmService);
247
        $userDao = new UserDao($this->tdbmService);
248
        $userBean = new UserBean('John Doe', '[email protected]', $countryDao->getById(2), 'john.doe');
249
        $userBean->setOrder(1); // Let's set a "protected keyword" column.
250
251
        $userDao->save($userBean);
252
253
        $this->assertNull($userBean->getManager());
254
    }
255
256
    /**
257
     * @depends testDaoGeneration
258
     */
259
    public function testDateTimeImmutableGetter()
260
    {
261
        $userDao = new UserDao($this->tdbmService);
262
        $user = $userDao->getById(1);
263
264
        $this->assertInstanceOf('\DateTimeImmutable', $user->getCreatedAt());
265
    }
266
267
    /**
268
     * @depends testDaoGeneration
269
     */
270
    public function testAssigningNewBeans()
271
    {
272
        $userDao = new UserDao($this->tdbmService);
273
        $countryBean = new CountryBean('Mexico');
274
        $userBean = new UserBean('Speedy Gonzalez', '[email protected]', $countryBean, 'speedy.gonzalez');
275
        $this->assertEquals($countryBean, $userBean->getCountry());
276
277
        $userDao->save($userBean);
278
    }
279
280
    /**
281
     * @depends testAssigningNewBeans
282
     */
283
    public function testUpdatingProtectedColumn()
284
    {
285
        $userDao = new UserDao($this->tdbmService);
286
        $userBean = $userDao->findOneByLogin('speedy.gonzalez');
287
        $userBean->setOrder(2);
288
        $userDao->save($userBean);
289
        $this->assertSame(2, $userBean->getOrder());
290
    }
291
292
    /**
293
     * @depends testDaoGeneration
294
     */
295
    public function testAssigningExistingRelationship()
296
    {
297
        $userDao = new UserDao($this->tdbmService);
298
        $user = $userDao->getById(1);
299
        $countryDao = new CountryDao($this->tdbmService);
300
        $country = $countryDao->getById(2);
301
302
        $user->setCountry($country);
303
        $this->assertEquals(TDBMObjectStateEnum::STATE_DIRTY, $user->_getStatus());
304
    }
305
306
    /**
307
     * @depends testDaoGeneration
308
     */
309
    public function testDirectReversedRelationship()
310
    {
311
        $countryDao = new CountryDao($this->tdbmService);
312
        $country = $countryDao->getById(1);
313
        $users = $country->getUsers();
314
315
        $arr = $users->toArray();
316
317
        $this->assertCount(1, $arr);
318
        $this->assertInstanceOf('TheCodingMachine\\TDBM\\Test\\Dao\\Bean\\UserBean', $arr[0]);
319
        $this->assertEquals('jean.dupont', $arr[0]->getLogin());
320
321
        $newUser = new UserBean('Speedy Gonzalez', '[email protected]', $country, 'speedy.gonzalez');
0 ignored issues
show
Unused Code introduced by
The assignment to $newUser is dead and can be removed.
Loading history...
322
        $users = $country->getUsers();
323
324
        $arr = $users->toArray();
325
326
        $this->assertCount(2, $arr);
327
        $this->assertInstanceOf('TheCodingMachine\\TDBM\\Test\\Dao\\Bean\\UserBean', $arr[1]);
328
        $this->assertEquals('speedy.gonzalez', $arr[1]->getLogin());
329
    }
330
331
    /**
332
     * @depends testDaoGeneration
333
     */
334
    public function testDeleteInDirectReversedRelationship()
335
    {
336
        $countryDao = new CountryDao($this->tdbmService);
337
        $country = $countryDao->getById(1);
338
339
        $userDao = new UserDao($this->tdbmService);
340
        $newUser = new UserBean('John Snow', '[email protected]', $country, 'john.snow');
341
        $userDao->save($newUser);
342
343
        $users = $country->getUsers();
344
345
        $arr = $users->toArray();
346
347
        $this->assertCount(2, $arr);
348
349
        $userDao->delete($arr[1]);
350
351
        $users = $country->getUsers();
352
        $arr = $users->toArray();
353
        $this->assertCount(1, $arr);
354
    }
355
356
    /**
357
     * @depends testDaoGeneration
358
     */
359
    public function testJointureGetters()
360
    {
361
        $roleDao = new RoleDao($this->tdbmService);
362
        $role = $roleDao->getById(1);
363
        $users = $role->getUsers();
364
365
        $this->assertCount(2, $users);
366
        $this->assertInstanceOf('TheCodingMachine\\TDBM\\Test\\Dao\\Bean\\UserBean', $users[0]);
367
368
        $rights = $role->getRights();
369
370
        $this->assertCount(2, $rights);
371
        $this->assertInstanceOf('TheCodingMachine\\TDBM\\Test\\Dao\\Bean\\RightBean', $rights[0]);
372
    }
373
374
    /**
375
     * @depends testDaoGeneration
376
     */
377
    public function testNestedIterationOnAlterableResultIterator()
378
    {
379
        $countryDao = new CountryDao($this->tdbmService);
380
        $country = $countryDao->getById(2);
381
382
        $count = 0;
383
        // Let's perform 2 nested calls to check that iterators do not melt.
384
        foreach ($country->getUsers() as $user) {
385
            foreach ($country->getUsers() as $user2) {
386
                $count++;
387
            }
388
        }
389
        // There are 3 users linked to country 2.
390
        $this->assertSame(9, $count);
391
    }
392
393
    /**
394
     * @depends testDaoGeneration
395
     */
396
    public function testNewBeanConstructor()
397
    {
398
        $role = new RoleBean('Newrole');
399
        $this->assertEquals(TDBMObjectStateEnum::STATE_DETACHED, $role->_getStatus());
400
    }
401
402
    /**
403
     * @depends testDaoGeneration
404
     */
405
    public function testJointureAdderOnNewBean()
406
    {
407
        $countryDao = new CountryDao($this->tdbmService);
408
        $country = $countryDao->getById(1);
409
        $user = new UserBean('Speedy Gonzalez', '[email protected]', $country, 'speedy.gonzalez');
410
        $role = new RoleBean('Mouse');
411
        $user->addRole($role);
412
        $roles = $user->getRoles();
413
        $this->assertCount(1, $roles);
414
        $role = $roles[0];
415
        $this->assertInstanceOf('TheCodingMachine\\TDBM\\Test\\Dao\\Bean\\RoleBean', $role);
416
        $users = $role->getUsers();
417
        $this->assertCount(1, $users);
418
        $this->assertEquals($user, $users[0]);
419
420
        $role->removeUser($user);
421
        $this->assertCount(0, $role->getUsers());
422
        $this->assertCount(0, $user->getRoles());
423
    }
424
425
    /**
426
     * @depends testDaoGeneration
427
     */
428
    public function testJointureDeleteBeforeGetters()
429
    {
430
        $roleDao = new RoleDao($this->tdbmService);
431
        $userDao = new UserDao($this->tdbmService);
432
        $role = $roleDao->getById(1);
433
        $user = $userDao->getById(1);
434
435
        // We call removeUser BEFORE calling getUsers
436
        // This should work as expected.
437
        $role->removeUser($user);
438
        $users = $role->getUsers();
439
440
        $this->assertCount(1, $users);
441
    }
442
443
    /**
444
     * @depends testDaoGeneration
445
     */
446
    public function testJointureMultiAdd()
447
    {
448
        $countryDao = new CountryDao($this->tdbmService);
449
        $country = $countryDao->getById(1);
450
        $user = new UserBean('Speedy Gonzalez', '[email protected]', $country, 'speedy.gonzalez');
451
        $role = new RoleBean('Mouse');
452
        $user->addRole($role);
453
        $role->addUser($user);
454
        $user->addRole($role);
455
456
        $this->assertCount(1, $user->getRoles());
457
    }
458
459
    /**
460
     * Step 1: we remove the role 1 from user 1 but save role 1.
461
     * Expected result: no save done.
462
     *
463
     * @depends testDaoGeneration
464
     */
465
    public function testJointureSave1()
466
    {
467
        $roleDao = new RoleDao($this->tdbmService);
468
        $role = $roleDao->getById(1);
469
        $userDao = new UserDao($this->tdbmService);
470
        $user = $userDao->getById(1);
471
472
        $this->assertTrue($user->hasRole($role));
473
        $this->assertTrue($role->hasUser($user));
474
        $user->removeRole($role);
475
        $this->assertFalse($user->hasRole($role));
476
        $this->assertFalse($role->hasUser($user));
477
        $roleDao->save($role);
478
479
        $this->assertEquals(TDBMObjectStateEnum::STATE_DIRTY, $user->_getStatus());
480
        $this->assertEquals(TDBMObjectStateEnum::STATE_LOADED, $role->_getStatus());
481
    }
482
483
    /**
484
     * Step 2: we check that nothing was saved
485
     * Expected result: no save done.
486
     *
487
     * @depends testJointureSave1
488
     */
489
    public function testJointureSave2()
490
    {
491
        $roleDao = new RoleDao($this->tdbmService);
492
        $role = $roleDao->getById(1);
493
        $this->assertCount(2, $role->getUsers());
494
    }
495
496
    /**
497
     * Step 3: we remove the role 1 from user 1 and save user 1.
498
     * Expected result: save done.
499
     *
500
     * @depends testJointureSave2
501
     */
502
    public function testJointureSave3()
503
    {
504
        $roleDao = new RoleDao($this->tdbmService);
505
        $role = $roleDao->getById(1);
506
        $userDao = new UserDao($this->tdbmService);
507
        $user = $userDao->getById(1);
508
509
        $this->assertCount(1, $user->getRoles());
510
        $user->removeRole($role);
511
        $this->assertCount(0, $user->getRoles());
512
        $userDao->save($user);
513
        $this->assertCount(0, $user->getRoles());
514
    }
515
516
    /**
517
     * Step 4: we check that save was done
518
     * Expected result: save done.
519
     *
520
     * @depends testJointureSave3
521
     */
522
    public function testJointureSave4()
523
    {
524
        $roleDao = new RoleDao($this->tdbmService);
525
        $role = $roleDao->getById(1);
526
        $this->assertCount(1, $role->getUsers());
527
        $userDao = new UserDao($this->tdbmService);
528
        $user = $userDao->getById(1);
529
        $this->assertCount(0, $user->getRoles());
530
    }
531
532
    /**
533
     * Step 5: we add the role 1 from user 1 and save user 1.
534
     * Expected result: save done.
535
     *
536
     * @depends testJointureSave4
537
     */
538
    public function testJointureSave5()
539
    {
540
        $roleDao = new RoleDao($this->tdbmService);
541
        $role = $roleDao->getById(1);
542
        $userDao = new UserDao($this->tdbmService);
543
        $user = $userDao->getById(1);
544
545
        $user->addRole($role);
546
        $this->assertCount(1, $user->getRoles());
547
        $userDao->save($user);
548
    }
549
550
    /**
551
     * Step 6: we check that save was done
552
     * Expected result: save done.
553
     *
554
     * @depends testJointureSave5
555
     */
556
    public function testJointureSave6()
557
    {
558
        $roleDao = new RoleDao($this->tdbmService);
559
        $role = $roleDao->getById(1);
560
        $this->assertCount(2, $role->getUsers());
561
        $userDao = new UserDao($this->tdbmService);
562
        $user = $userDao->getById(1);
563
        $this->assertCount(1, $user->getRoles());
564
    }
565
566
    /**
567
     * Step 7: we add a new role to user 1 and save user 1.
568
     * Expected result: save done, including the new role.
569
     *
570
     * @depends testJointureSave6
571
     */
572
    public function testJointureSave7()
573
    {
574
        $role = new RoleBean('my new role');
575
        $userDao = new UserDao($this->tdbmService);
576
        $user = $userDao->getById(1);
577
578
        $user->addRole($role);
579
        $userDao->save($user);
580
581
        $this->assertEquals(TDBMObjectStateEnum::STATE_LOADED, $role->_getStatus());
582
    }
583
584
    /**
585
     * Step 8: we check that save was done
586
     * Expected result: save done.
587
     *
588
     * @depends testJointureSave7
589
     */
590
    public function testJointureSave8()
591
    {
592
        $roleDao = new RoleDao($this->tdbmService);
593
        $userDao = new UserDao($this->tdbmService);
594
        $user = $userDao->getById(1);
595
596
        $roles = $user->getRoles();
597
        foreach ($roles as $role) {
598
            if ($role->getName() === 'my new role') {
599
                $selectedRole = $role;
600
                break;
601
            }
602
        }
603
        $this->assertNotNull($selectedRole);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $selectedRole does not seem to be defined for all execution paths leading up to this point.
Loading history...
604
605
        $this->assertCount(2, $user->getRoles());
606
607
        // Expected: relationship removed!
608
        $roleDao->delete($selectedRole);
609
610
        $this->assertCount(1, $user->getRoles());
611
    }
612
613
    /**
614
     * Step 9: Let's test the setXXX method.
615
     *
616
     * @depends testJointureSave8
617
     */
618
    public function testJointureSave9()
619
    {
620
        $roleDao = new RoleDao($this->tdbmService);
621
        $userDao = new UserDao($this->tdbmService);
622
        $user = $userDao->getById(1);
623
624
        // At this point, user 1 is linked to role 1.
625
        // Let's bind it to role 2.
626
        $user->setRoles([$roleDao->getById(2)]);
627
        $userDao->save($user);
628
        $this->assertTrue($user->hasRole($roleDao->getById(2)));
629
    }
630
631
    /**
632
     * Step 10: Let's check results of 9.
633
     *
634
     * @depends testJointureSave9
635
     */
636
    public function testJointureSave10()
637
    {
638
        $userDao = new UserDao($this->tdbmService);
639
        $user = $userDao->getById(1);
640
641
        $roles = $user->getRoles();
642
643
        $this->assertCount(1, $roles);
644
        $this->assertEquals(2, $roles[0]->getId());
645
    }
646
647
    /**
648
     * @depends testDaoGeneration
649
     */
650
    public function testFindOrderBy()
651
    {
652
        $userDao = new TestUserDao($this->tdbmService);
653
        $users = $userDao->getUsersByAlphabeticalOrder();
654
655
        $this->assertCount(6, $users);
656
        $this->assertEquals('bill.shakespeare', $users[0]->getLogin());
657
        $this->assertEquals('jean.dupont', $users[1]->getLogin());
658
659
        $users = $userDao->getUsersByCountryOrder();
660
        $this->assertCount(6, $users);
661
        $countryName1 = $users[0]->getCountry()->getLabel();
662
        for ($i = 1; $i < 6; $i++) {
663
            $countryName2 = $users[$i]->getCountry()->getLabel();
664
            $this->assertLessThanOrEqual(0, strcmp($countryName1, $countryName2));
665
            $countryName1 = $countryName2;
666
        }
667
    }
668
669
    /**
670
     * @depends testDaoGeneration
671
     */
672
    public function testFindFromSqlOrderBy()
673
    {
674
        $userDao = new TestUserDao($this->tdbmService);
675
        $users = $userDao->getUsersFromSqlByAlphabeticalOrder();
676
677
        $this->assertCount(6, $users);
678
        $this->assertEquals('bill.shakespeare', $users[0]->getLogin());
679
        $this->assertEquals('jean.dupont', $users[1]->getLogin());
680
681
        $users = $userDao->getUsersFromSqlByCountryOrder();
682
        $this->assertCount(6, $users);
683
        $countryName1 = $users[0]->getCountry()->getLabel();
684
        for ($i = 1; $i < 6; $i++) {
685
            $countryName2 = $users[$i]->getCountry()->getLabel();
686
            $this->assertLessThanOrEqual(0, strcmp($countryName1, $countryName2));
687
            $countryName1 = $countryName2;
688
        }
689
    }
690
691
    /**
692
     * @depends testDaoGeneration
693
     */
694
    public function testFindFromSqlOrderByOnInheritedBean()
695
    {
696
        $articleDao = new TestArticleDao($this->tdbmService);
697
        $articles = $articleDao->getArticlesByUserLogin();
698
699
        foreach ($articles as $article) {
700
            var_dump($article);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($article) looks like debug code. Are you sure you do not want to remove it?
Loading history...
701
        }
702
        $this->assertCount(0, $articles);
703
    }
704
705
706
    /**
707
     * @depends testDaoGeneration
708
     */
709
    public function testFindFromSqlOrderByJoinRole()
710
    {
711
        $roleDao = new TestRoleDao($this->tdbmService);
712
        $roles = $roleDao->getRolesByRightCanSing('roles.name DESC');
713
714
        $this->assertCount(2, $roles);
715
        $this->assertEquals('Singers', $roles[0]->getName());
716
        $this->assertEquals('Admins', $roles[1]->getName());
717
    }
718
719
    /**
720
     * @depends testDaoGeneration
721
     */
722
    public function testFindFromRawSqlOrderByUserCount()
723
    {
724
        $countryDao = new TestCountryDao($this->tdbmService);
725
        $countries = $countryDao->getCountriesByUserCount();
726
727
        $this->assertCount(4, $countries);
728
        for ($i = 1; $i < count($countries); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
729
            $this->assertLessThanOrEqual($countries[$i - 1]->getUsers()->count(), $countries[$i]->getUsers()->count());
730
        }
731
    }
732
733
    /**
734
     * @depends testDaoGeneration
735
     */
736
    public function testFindFromRawSqlWithUnion()
737
    {
738
        $countryDao = new TestCountryDao($this->tdbmService);
739
        $countries = $countryDao->getCountriesUsingUnion();
740
741
        $this->assertCount(2, $countries);
742
        $this->assertEquals(1, $countries[0]->getId());
743
    }
744
745
    /**
746
     * @depends testDaoGeneration
747
     */
748
    public function testFindFromRawSqlWithSimpleQuery()
749
    {
750
        $countryDao = new TestCountryDao($this->tdbmService);
751
        $countries = $countryDao->getCountriesUsingSimpleQuery();
752
753
        $this->assertCount(1, $countries);
754
        $this->assertEquals(1, $countries[0]->getId());
755
    }
756
757
    /**
758
     * @depends testDaoGeneration
759
     */
760
    public function testFindFromRawSqlWithDistinctQuery()
761
    {
762
        $countryDao = new TestCountryDao($this->tdbmService);
763
        $countries = $countryDao->getCountriesUsingDistinctQuery();
764
765
        $this->assertCount(1, $countries);
766
        $this->assertEquals(2, $countries[0]->getId());
767
    }
768
769
    /**
770
     * @depends testDaoGeneration
771
     */
772
    public function testFindFilters()
773
    {
774
        $userDao = new TestUserDao($this->tdbmService);
775
        $users = $userDao->getUsersByLoginStartingWith('bill');
776
777
        $this->assertCount(1, $users);
778
        $this->assertEquals('bill.shakespeare', $users[0]->getLogin());
779
    }
780
781
    /**
782
     * @expectedException \TheCodingMachine\TDBM\TDBMException
783
     * @depends testDaoGeneration
784
     */
785
    public function testFindMode()
786
    {
787
        $userDao = new TestUserDao($this->tdbmService);
788
        $users = $userDao->getUsersByLoginStartingWith('bill', TDBMService::MODE_CURSOR);
789
790
        $users[0];
791
    }
792
793
    /**
794
     * @depends testDaoGeneration
795
     */
796
    public function testFindAll()
797
    {
798
        $userDao = new TestUserDao($this->tdbmService);
799
        $users = $userDao->findAll();
800
801
        $this->assertCount(6, $users);
802
    }
803
804
    /**
805
     * @depends testDaoGeneration
806
     */
807
    public function testFindOne()
808
    {
809
        $userDao = new TestUserDao($this->tdbmService);
810
        $user = $userDao->getUserByLogin('bill.shakespeare');
811
812
        $this->assertEquals('bill.shakespeare', $user->getLogin());
813
    }
814
815
    /**
816
     * @depends testDaoGeneration
817
     */
818
    public function testJsonEncodeBean()
819
    {
820
        $userDao = new TestUserDao($this->tdbmService);
821
        $user = $userDao->getUserByLogin('bill.shakespeare');
822
823
        $jsonEncoded = json_encode($user);
824
        $userDecoded = json_decode($jsonEncoded, true);
825
826
        $this->assertEquals('bill.shakespeare', $userDecoded['login']);
827
828
        // test serialization of dates.
829
        $this->assertTrue(is_string($userDecoded['createdAt']));
830
        $this->assertEquals('2015-10-24', (new \DateTimeImmutable($userDecoded['createdAt']))->format('Y-m-d'));
831
        $this->assertNull($userDecoded['modifiedAt']);
832
833
        // testing many to 1 relationships
834
        $this->assertEquals('UK', $userDecoded['country']['label']);
835
836
        // testing many to many relationships
837
        $this->assertCount(1, $userDecoded['roles']);
838
        $this->assertArrayNotHasKey('users', $userDecoded['roles'][0]);
839
        $this->assertArrayNotHasKey('rights', $userDecoded['roles'][0]);
840
    }
841
842
    /**
843
     * @depends testDaoGeneration
844
     */
845
    public function testNullableForeignKey()
846
    {
847
        $userDao = new TestUserDao($this->tdbmService);
848
        $user = $userDao->getUserByLogin('john.smith');
849
850
        $this->assertNull($user->getManager());
851
852
        $jsonEncoded = json_encode($user);
853
        $userDecoded = json_decode($jsonEncoded, true);
854
855
        $this->assertNull($userDecoded['manager']);
856
    }
857
858
    /**
859
     * Test that setting (and saving) objects' references (foreign keys relations) to null is working.
860
     *
861
     * @depends testDaoGeneration
862
     */
863
    public function testSetToNullForeignKey()
864
    {
865
        $userDao = new TestUserDao($this->tdbmService);
866
        $user = $userDao->getUserByLogin('john.smith');
867
        $manager = $userDao->getUserByLogin('jean.dupont');
868
869
        $user->setManager($manager);
870
        $userDao->save($user);
871
872
        $user->setManager(null);
873
        $userDao->save($user);
874
        $this->assertNull($user->getManager());
875
    }
876
877
    /**
878
     * @depends testDaoGeneration
879
     * @expectedException \Mouf\Database\SchemaAnalyzer\SchemaAnalyzerTableNotFoundException
880
     * @expectedExceptionMessage Could not find table 'contacts'. Did you mean 'contact'?
881
     */
882
    public function testQueryOnWrongTableName()
883
    {
884
        $userDao = new TestUserDao($this->tdbmService);
885
        $users = $userDao->getUsersWrongTableName();
886
        $users->count();
887
    }
888
889
    /**
890
     * @depends testDaoGeneration
891
     */
892
    /*public function testQueryNullForeignKey()
893
    {
894
        $userDao = new TestUserDao($this->tdbmService);
895
        $users = $userDao->getUsersByManagerId(null);
896
        $this->assertCount(3, $users);
897
    }*/
898
899
    /**
900
     * @depends testDaoGeneration
901
     */
902
    public function testInnerJsonEncode()
903
    {
904
        $userDao = new TestUserDao($this->tdbmService);
905
        $user = $userDao->getUserByLogin('bill.shakespeare');
906
907
        $jsonEncoded = json_encode(['user' => $user]);
908
        $msgDecoded = json_decode($jsonEncoded, true);
909
910
        $this->assertEquals('bill.shakespeare', $msgDecoded['user']['login']);
911
    }
912
913
    /**
914
     * @depends testDaoGeneration
915
     */
916
    public function testArrayJsonEncode()
917
    {
918
        $userDao = new TestUserDao($this->tdbmService);
919
        $users = $userDao->getUsersByLoginStartingWith('bill');
920
921
        $jsonEncoded = json_encode($users);
922
        $msgDecoded = json_decode($jsonEncoded, true);
923
924
        $this->assertCount(1, $msgDecoded);
925
    }
926
927
    /**
928
     * @depends testDaoGeneration
929
     */
930
    public function testCursorJsonEncode()
931
    {
932
        $userDao = new TestUserDao($this->tdbmService);
933
        $users = $userDao->getUsersByLoginStartingWith('bill', TDBMService::MODE_CURSOR);
934
935
        $jsonEncoded = json_encode($users);
936
        $msgDecoded = json_decode($jsonEncoded, true);
937
938
        $this->assertCount(1, $msgDecoded);
939
    }
940
941
    /**
942
     * @depends testDaoGeneration
943
     */
944
    public function testPageJsonEncode()
945
    {
946
        $userDao = new TestUserDao($this->tdbmService);
947
        $users = $userDao->getUsersByLoginStartingWith('bill');
948
949
        $jsonEncoded = json_encode($users->take(0, 1));
950
        $msgDecoded = json_decode($jsonEncoded, true);
951
952
        $this->assertCount(1, $msgDecoded);
953
    }
954
955
    /**
956
     * @depends testDaoGeneration
957
     */
958
    public function testFirst()
959
    {
960
        $userDao = new TestUserDao($this->tdbmService);
961
        $users = $userDao->getUsersByLoginStartingWith('bill');
962
963
        $bill = $users->first();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $bill is correct as $users->first() targeting TheCodingMachine\TDBM\ResultIterator::first() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
964
        $this->assertEquals('bill.shakespeare', $bill->getLogin());
965
    }
966
967
    /**
968
     * @depends testDaoGeneration
969
     */
970
    public function testFirstNull()
971
    {
972
        $userDao = new TestUserDao($this->tdbmService);
973
        $users = $userDao->getUsersByLoginStartingWith('mike');
974
975
        $user = $users->first();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $user is correct as $users->first() targeting TheCodingMachine\TDBM\ResultIterator::first() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
976
        $this->assertNull($user);
977
    }
978
979
    /**
980
     * @depends testDaoGeneration
981
     */
982
    public function testCloneBeanAttachedBean()
983
    {
984
        $userDao = new TestUserDao($this->tdbmService);
985
        $user = $userDao->getUserByLogin('bill.shakespeare');
986
        $this->assertEquals(4, $user->getId());
987
        $user2 = clone $user;
988
        $this->assertNull($user2->getId());
989
        $this->assertEquals('bill.shakespeare', $user2->getLogin());
990
        $this->assertEquals('Bill Shakespeare', $user2->getName());
991
        $this->assertEquals('UK', $user2->getCountry()->getLabel());
992
993
        // MANY 2 MANY must be duplicated
994
        $this->assertEquals('Writers', $user2->getRoles()[0]->getName());
995
996
        // Let's test saving this clone
997
        $user2->setLogin('william.shakespeare');
998
        $userDao->save($user2);
999
1000
        $user3 = $userDao->getUserByLogin('william.shakespeare');
1001
        $this->assertTrue($user3 === $user2);
1002
        $userDao->delete($user3);
1003
1004
        // Finally, let's test the origin user still exists!
1005
        $user4 = $userDao->getUserByLogin('bill.shakespeare');
1006
        $this->assertEquals('bill.shakespeare', $user4->getLogin());
1007
    }
1008
1009
    /**
1010
     * @depends testDaoGeneration
1011
     */
1012
    public function testCloneNewBean()
1013
    {
1014
        $countryDao = new CountryDao($this->tdbmService);
1015
        $roleDao = new RoleDao($this->tdbmService);
1016
        $role = $roleDao->getById(1);
1017
1018
        $userBean = new UserBean('John Doe', '[email protected]', $countryDao->getById(2), 'john.doe');
1019
        $userBean->addRole($role);
1020
1021
        $user2 = clone $userBean;
1022
1023
        $this->assertNull($user2->getId());
1024
        $this->assertEquals('john.doe', $user2->getLogin());
1025
        $this->assertEquals('John Doe', $user2->getName());
1026
        $this->assertEquals('UK', $user2->getCountry()->getLabel());
1027
1028
        // MANY 2 MANY must be duplicated
1029
        $this->assertEquals($role->getName(), $user2->getRoles()[0]->getName());
1030
    }
1031
1032
    /**
1033
     * @depends testDaoGeneration
1034
     */
1035
    public function testCascadeDelete()
1036
    {
1037
        $userDao = new TestUserDao($this->tdbmService);
1038
        $countryDao = new CountryDao($this->tdbmService);
1039
1040
        $spain = new CountryBean('Spain');
1041
        $sanchez = new UserBean('Manuel Sanchez', '[email protected]', $spain, 'manuel.sanchez');
1042
1043
        $countryDao->save($spain);
1044
        $userDao->save($sanchez);
1045
1046
        $speedy2 = $userDao->getUserByLogin('manuel.sanchez');
1047
        $this->assertTrue($sanchez === $speedy2);
1048
1049
        $exceptionTriggered = false;
1050
        try {
1051
            $countryDao->delete($spain);
1052
        } catch (ForeignKeyConstraintViolationException $e) {
1053
            $exceptionTriggered = true;
1054
        }
1055
        $this->assertTrue($exceptionTriggered);
1056
1057
        $countryDao->delete($spain, true);
1058
1059
        // Let's check that speed gonzalez was removed.
1060
        $speedy3 = $userDao->getUserByLogin('manuel.sanchez');
1061
        $this->assertNull($speedy3);
1062
    }
1063
1064
    /**
1065
     * @depends testDaoGeneration
1066
     */
1067
    public function testDiscardChanges()
1068
    {
1069
        $contactDao = new ContactDao($this->tdbmService);
1070
        $contactBean = $contactDao->getById(1);
1071
1072
        $oldName = $contactBean->getName();
1073
1074
        $contactBean->setName('MyNewName');
1075
1076
        $contactBean->discardChanges();
1077
1078
        $this->assertEquals($oldName, $contactBean->getName());
1079
    }
1080
1081
    /**
1082
     * @expectedException \TheCodingMachine\TDBM\TDBMException
1083
     * @depends testDaoGeneration
1084
     */
1085
    public function testDiscardChangesOnNewBeanFails()
1086
    {
1087
        $person = new PersonBean('John Foo', new \DateTimeImmutable());
1088
        $person->discardChanges();
1089
    }
1090
1091
    /**
1092
     * @expectedException \TheCodingMachine\TDBM\TDBMException
1093
     * @depends testDaoGeneration
1094
     */
1095
    public function testDiscardChangesOnDeletedBeanFails()
1096
    {
1097
        $userDao = new TestUserDao($this->tdbmService);
1098
        $countryDao = new CountryDao($this->tdbmService);
1099
1100
        $sanchez = new UserBean('Manuel Sanchez', '[email protected]', $countryDao->getById(1), 'manuel.sanchez');
1101
1102
        $userDao->save($sanchez);
1103
1104
        $userDao->delete($sanchez);
1105
1106
        // Cannot discard changes on a bean that is already deleted.
1107
        $sanchez->discardChanges();
1108
    }
1109
1110
    /**
1111
     * @depends testDaoGeneration
1112
     */
1113
    public function testUniqueIndexBasedSearch()
1114
    {
1115
        $userDao = new UserDao($this->tdbmService);
1116
        $user = $userDao->findOneByLogin('bill.shakespeare');
1117
1118
        $this->assertEquals('bill.shakespeare', $user->getLogin());
1119
        $this->assertEquals('Bill Shakespeare', $user->getName());
1120
    }
1121
1122
    /**
1123
     * @depends testDaoGeneration
1124
     */
1125
    public function testFindOneByRetunsNull()
1126
    {
1127
        // Let's assert that the findOneBy... methods can return null.
1128
        $userDao = new UserDao($this->tdbmService);
1129
        $userBean = $userDao->findOneByLogin('not_exist');
1130
1131
        $this->assertNull($userBean);
1132
    }
1133
1134
    /**
1135
     * @depends testDaoGeneration
1136
     */
1137
    public function testMultiColumnsIndexBasedSearch()
1138
    {
1139
        $countryDao = new CountryDao($this->tdbmService);
1140
        $userDao = new UserDao($this->tdbmService);
1141
        $users = $userDao->findByStatusAndCountry('on', $countryDao->getById(1));
1142
1143
        $this->assertEquals('jean.dupont', $users[0]->getLogin());
1144
    }
1145
1146
    /**
1147
     * @depends testDaoGeneration
1148
     */
1149
    public function testPartialMultiColumnsIndexBasedSearch()
1150
    {
1151
        $userDao = new UserDao($this->tdbmService);
1152
        $users = $userDao->findByStatusAndCountry('on');
1153
1154
        $this->assertCount(2, $users);
1155
    }
1156
1157
    /**
1158
     * @depends testDaoGeneration
1159
     */
1160
    public function testCreationInNullableDate()
1161
    {
1162
        $roleDao = new RoleDao($this->tdbmService);
1163
1164
        $role = new RoleBean('newbee');
1165
        $roleDao->save($role);
1166
1167
        $this->assertNull($role->getCreatedAt());
1168
    }
1169
1170
    /**
1171
     * @depends testDaoGeneration
1172
     */
1173
    public function testUpdateInNullableDate()
1174
    {
1175
        $roleDao = new RoleDao($this->tdbmService);
1176
1177
        $role = new RoleBean('newbee');
1178
        $roleDao->save($role);
1179
1180
        $role->setCreatedAt(null);
1181
        $roleDao->save($role);
1182
        $this->assertNull($role->getCreatedAt());
1183
    }
1184
1185
    /**
1186
     * @depends testDaoGeneration
1187
     */
1188
    public function testFindFromSql()
1189
    {
1190
        $roleDao = new TestRoleDao($this->tdbmService);
1191
1192
        $roles = $roleDao->getRolesByRightCanSing();
1193
        $this->assertCount(2, $roles);
1194
        $this->assertInstanceOf(RoleBean::class, $roles[0]);
1195
    }
1196
1197
    /**
1198
     * @depends testDaoGeneration
1199
     */
1200
    public function testFindOneFromSql()
1201
    {
1202
        $roleDao = new TestRoleDao($this->tdbmService);
1203
1204
        $role = $roleDao->getRoleByRightCanSingAndNameSinger();
1205
        $this->assertInstanceOf(RoleBean::class, $role);
1206
    }
1207
1208
    /**
1209
     * @depends testDaoGeneration
1210
     */
1211
    public function testCreateEmptyExtendedBean()
1212
    {
1213
        // This test cases checks issue https://github.com/thecodingmachine/database.tdbm/issues/92
1214
1215
        $dogDao = new DogDao($this->tdbmService);
1216
1217
        // We are not filling no field that is part of dog table.
1218
        $dog = new DogBean('Youki');
1219
        $dog->setOrder(1);
1220
1221
        $dogDao->save($dog);
1222
        $this->assertNull($dog->getRace());
1223
    }
1224
1225
    /**
1226
     * @depends testCreateEmptyExtendedBean
1227
     */
1228
    public function testFetchEmptyExtendedBean()
1229
    {
1230
        // This test cases checks issue https://github.com/thecodingmachine/database.tdbm/issues/92
1231
1232
        $animalDao = new AnimalDao($this->tdbmService);
1233
1234
        // We are not filling no field that is part of dog table.
1235
        $animalBean = $animalDao->getById(1);
1236
1237
        $this->assertInstanceOf(DogBean::class, $animalBean);
1238
    }
1239
1240
    /**
1241
     * @depends testDaoGeneration
1242
     */
1243
    public function testTwoBranchesHierarchy()
1244
    {
1245
        // This test cases checks issue https://github.com/thecodingmachine/mouf/issues/131
1246
1247
        $catDao = new CatDao($this->tdbmService);
1248
1249
        // We are not filling no field that is part of dog table.
1250
        $cat = new CatBean('Mew');
1251
        $cat->setOrder(2);
1252
1253
        $catDao->save($cat);
1254
        $this->assertNotNull($cat->getId());
1255
    }
1256
1257
    /**
1258
     * @depends testTwoBranchesHierarchy
1259
     */
1260
    public function testFetchTwoBranchesHierarchy()
1261
    {
1262
        // This test cases checks issue https://github.com/thecodingmachine/mouf/issues/131
1263
1264
        $animalDao = new AnimalDao($this->tdbmService);
1265
1266
        $animalBean = $animalDao->getById(2);
1267
1268
        $this->assertInstanceOf(CatBean::class, $animalBean);
1269
        /* @var $animalBean CatBean */
1270
        $animalBean->setCutenessLevel(999);
1271
        $animalBean->setUppercaseColumn('foobar');
1272
1273
        $animalDao->save($animalBean);
1274
    }
1275
1276
    /**
1277
     * @depends testDaoGeneration
1278
     */
1279
    public function testExceptionOnGetById()
1280
    {
1281
        $countryDao = new CountryDao($this->tdbmService);
1282
        $this->expectException(\TypeError::class);
1283
        $countryDao->getById(null);
1284
    }
1285
1286
    /**
1287
     * @depends testDaoGeneration
1288
     */
1289
    public function testDisconnectedManyToOne()
1290
    {
1291
        // This test cases checks issue https://github.com/thecodingmachine/database.tdbm/issues/99
1292
1293
        $country = new CountryBean('Spain');
1294
1295
        $user = new UserBean('John Doe', '[email protected]', $country, 'john.doe');
1296
1297
        $this->assertCount(1, $country->getUsers());
1298
        $this->assertSame($user, $country->getUsers()[0]);
1299
    }
1300
1301
    /**
1302
     * @depends testDaoGeneration
1303
     */
1304
    public function testOrderByExternalCol()
1305
    {
1306
        // This test cases checks issue https://github.com/thecodingmachine/database.tdbm/issues/106
1307
1308
        $userDao = new TestUserDao($this->tdbmService);
1309
        $users = $userDao->getUsersByCountryName();
1310
1311
        $this->assertEquals('UK', $users[0]->getCountry()->getLabel());
1312
    }
1313
1314
    /**
1315
     * @depends testDaoGeneration
1316
     */
1317
    public function testResultIteratorSort()
1318
    {
1319
        $userDao = new UserDao($this->tdbmService);
1320
        $users = $userDao->findAll()->withOrder('country.label DESC');
1321
1322
        $this->assertEquals('UK', $users[0]->getCountry()->getLabel());
1323
1324
        $users = $users->withOrder('country.label ASC');
1325
        $this->assertEquals('France', $users[0]->getCountry()->getLabel());
1326
    }
1327
1328
    /**
1329
     * @depends testDaoGeneration
1330
     */
1331
    public function testResultIteratorWithParameters()
1332
    {
1333
        $userDao = new TestUserDao($this->tdbmService);
1334
        $users = $userDao->getUsersByLoginStartingWith()->withParameters(['login' => 'bill%']);
1335
        $this->assertEquals('bill.shakespeare', $users[0]->getLogin());
1336
1337
        $users = $users->withParameters(['login' => 'jean%']);
1338
        $this->assertEquals('jean.dupont', $users[0]->getLogin());
1339
    }
1340
1341
    /**
1342
     * @depends testDaoGeneration
1343
     */
1344
    public function testOrderByExpression()
1345
    {
1346
        $userDao = new TestUserDao($this->tdbmService);
1347
        $users = $userDao->getUsersByReversedCountryName();
1348
1349
        $this->assertEquals('Jamaica', $users[0]->getCountry()->getLabel());
1350
    }
1351
1352
    /**
1353
     * @depends testDaoGeneration
1354
     */
1355
    public function testOrderByException()
1356
    {
1357
        $userDao = new TestUserDao($this->tdbmService);
1358
        $users = $userDao->getUsersByInvalidOrderBy();
1359
        $this->expectException(TDBMInvalidArgumentException::class);
1360
        $user = $users[0];
0 ignored issues
show
Unused Code introduced by
The assignment to $user is dead and can be removed.
Loading history...
1361
    }
1362
1363
    /**
1364
     * @depends testDaoGeneration
1365
     */
1366
    public function testOrderByProtectedColumn()
1367
    {
1368
        $animalDao = new AnimalDao($this->tdbmService);
1369
        $animals = $animalDao->findAll();
1370
        $animals = $animals->withOrder('`order` ASC');
1371
1372
        $this->assertInstanceOf(DogBean::class, $animals[0]);
1373
        $this->assertInstanceOf(CatBean::class, $animals[1]);
1374
1375
        $animals = $animals->withOrder('`order` DESC');
1376
1377
        $this->assertInstanceOf(CatBean::class, $animals[0]);
1378
        $this->assertInstanceOf(DogBean::class, $animals[1]);
1379
    }
1380
1381
    /**
1382
     * @depends testDaoGeneration
1383
     */
1384
    public function testGetOnAllNullableValues()
1385
    {
1386
        // Tests that a get performed on a column that has only nullable fields succeeds.
1387
        $allNullable = new AllNullableBean();
1388
        $this->assertNull($allNullable->getId());
1389
        $this->assertNull($allNullable->getLabel());
1390
        $this->assertNull($allNullable->getCountry());
1391
    }
1392
1393
    /**
1394
     * @depends testDaoGeneration
1395
     */
1396
    public function testExceptionOnMultipleInheritance()
1397
    {
1398
        $connection = self::getConnection();
1399
        self::insert($connection, 'animal', [
1400
            'id' => 99, 'name' => 'Snoofield',
1401
        ]);
1402
        self::insert($connection, 'dog', [
1403
            'id' => 99, 'race' => 'dog',
1404
        ]);
1405
        self::insert($connection, 'cat', [
1406
            'id' => 99, 'cuteness_level' => 0,
1407
        ]);
1408
1409
        $catched = false;
1410
        try {
1411
            $animalDao = new AnimalDao($this->tdbmService);
1412
            $animalDao->getById(99);
1413
        } catch (TDBMInheritanceException $e) {
1414
            $catched = true;
1415
        }
1416
        $this->assertTrue($catched, 'Exception TDBMInheritanceException was not caught');
1417
1418
        self::delete($connection, 'cat', ['id' => 99]);
1419
        self::delete($connection, 'dog', ['id' => 99]);
1420
        self::delete($connection, 'animal', ['id' => 99]);
1421
    }
1422
1423
    /**
1424
     * @depends testDaoGeneration
1425
     */
1426
    public function testReferenceNotSaved()
1427
    {
1428
        $boatDao = new BoatDao($this->tdbmService);
1429
1430
        $country = new CountryBean('Atlantis');
1431
        $boat = new BoatBean($country, 'Titanic');
1432
1433
        $boatDao->save($boat);
1434
        $this->assertNotNull($country->getId());
1435
    }
1436
1437
    /**
1438
     * @depends testReferenceNotSaved
1439
     */
1440
    public function testUniqueIndexOnForeignKeyThenScalar()
1441
    {
1442
        $boatDao = new BoatDao($this->tdbmService);
1443
        $countryDao = new CountryDao($this->tdbmService);
1444
1445
        $countryBean = $countryDao->findOneByLabel('Atlantis');
1446
        $boatBean = $boatDao->findOneByAnchorageCountryAndName($countryBean, 'Titanic');
1447
1448
        $this->assertNotNull($boatBean);
1449
    }
1450
1451
    /**
1452
     * @depends testDaoGeneration
1453
     */
1454
    public function testReferenceDeleted()
1455
    {
1456
        $countryDao = new CountryDao($this->tdbmService);
1457
        $boatDao = new BoatDao($this->tdbmService);
1458
1459
        $country = new CountryBean('Bikini Bottom');
1460
        $countryDao->save($country);
1461
1462
        $boat = new BoatBean($country, 'Squirrel boat');
1463
        $countryDao->delete($country);
1464
1465
        $this->expectException(TDBMMissingReferenceException::class);
1466
        $boatDao->save($boat);
1467
    }
1468
1469
    /**
1470
     * @depends testDaoGeneration
1471
     */
1472
    public function testCyclicReferenceWithInheritance()
1473
    {
1474
        $userDao = new UserDao($this->tdbmService);
1475
1476
        $country = new CountryBean('Norrisland');
1477
        $user = new UserBean('Chuck Norris', '[email protected]', $country, 'chuck.norris');
1478
1479
        $user->setManager($user);
1480
1481
        $this->expectException(TDBMCyclicReferenceException::class);
1482
        $userDao->save($user);
1483
    }
1484
1485
    /**
1486
     * @depends testDaoGeneration
1487
     */
1488
    public function testCyclicReference()
1489
    {
1490
        $categoryDao = new CategoryDao($this->tdbmService);
1491
1492
        $category = new CategoryBean('Root');
1493
1494
        $category->setParent($category);
1495
1496
        $this->expectException(TDBMCyclicReferenceException::class);
1497
        $categoryDao->save($category);
1498
    }
1499
1500
    /**
1501
     * @depends testDaoGeneration
1502
     */
1503
    public function testCorrectTypeForPrimaryKeyAfterSave()
1504
    {
1505
        // PosqtgreSQL does not particularly like empty inserts (i.e.: "INSERT INTO all_nullable () VALUES ()" )
1506
        $this->onlyMySql();
1507
1508
        $allNullableDao = new AllNullableDao($this->tdbmService);
1509
        $allNullable = new AllNullableBean();
1510
        $allNullableDao->save($allNullable);
1511
        $id = $allNullable->getId();
1512
1513
        $this->assertTrue(is_int($id));
1514
    }
1515
1516
    /**
1517
     * @depends testDaoGeneration
1518
     */
1519
    public function testPSR2Compliance()
1520
    {
1521
        $process = new Process('vendor/bin/php-cs-fixer fix src/Test/  --dry-run --diff --rules=@PSR2');
0 ignored issues
show
Bug introduced by
'vendor/bin/php-cs-fixer...n --diff --rules=@PSR2' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1521
        $process = new Process(/** @scrutinizer ignore-type */ 'vendor/bin/php-cs-fixer fix src/Test/  --dry-run --diff --rules=@PSR2');
Loading history...
1522
        $process->run();
1523
1524
        // executes after the command finishes
1525
        if (!$process->isSuccessful()) {
1526
            echo $process->getOutput();
1527
            $this->fail('Generated code is not PSR-2 compliant');
1528
        }
1529
        $this->assertTrue($process->isSuccessful());
1530
    }
1531
1532
    /**
1533
     * @depends testDaoGeneration
1534
     */
1535
    public function testFindOneByGeneration()
1536
    {
1537
        $reflectionMethod = new \ReflectionMethod(UserBaseDao::class, 'findOneByLogin');
1538
        $parameters = $reflectionMethod->getParameters();
1539
1540
        $this->assertCount(2, $parameters);
1541
        $this->assertSame('login', $parameters[0]->getName());
1542
        $this->assertSame('additionalTablesFetch', $parameters[1]->getName());
1543
    }
1544
1545
    /**
1546
     * @depends testDaoGeneration
1547
     */
1548
    public function testUuid()
1549
    {
1550
        $article = new ArticleBean('content');
1551
        $this->assertSame('content', $article->getContent());
1552
        $this->assertNotEmpty($article->getId());
1553
        $uuid = Uuid::fromString($article->getId());
1554
        $this->assertSame(1, $uuid->getVersion());
1555
    }
1556
1557
    /**
1558
     * @depends testDaoGeneration
1559
     */
1560
    public function testUuidv4()
1561
    {
1562
        $article = new Article2Bean('content');
1563
        $this->assertSame('content', $article->getContent());
1564
        $this->assertNotEmpty($article->getId());
1565
        $uuid = Uuid::fromString($article->getId());
1566
        $this->assertSame(4, $uuid->getVersion());
1567
    }
1568
1569
    /**
1570
     * @depends testDaoGeneration
1571
     */
1572
    public function testTypeHintedConstructors()
1573
    {
1574
        $userBaseBeanReflectionConstructor = new \ReflectionMethod(UserBaseBean::class, '__construct');
1575
        $nameParam = $userBaseBeanReflectionConstructor->getParameters()[0];
1576
1577
        $this->assertSame('string', (string)$nameParam->getType());
1578
    }
1579
1580
    /**
1581
     * @depends testDaoGeneration
1582
     */
1583
    public function testSaveTransaction()
1584
    {
1585
        $countryDao = new CountryDao($this->tdbmService);
1586
1587
        $boatDao = new BoatDao($this->tdbmService);
1588
        $boatBean = $boatDao->getById(1);
1589
        $boatBean->setName('Bismark');
1590
1591
        $boatBean->getCountry();
1592
1593
        // Let's insert a row without telling TDBM to trigger an error!
1594
        self::insert($this->getConnection(), 'sailed_countries', [
1595
            'boat_id' => 1,
1596
            'country_id' => 2
1597
        ]);
1598
1599
        $boatBean->addCountry($countryDao->getById(2));
1600
1601
        $this->expectException(UniqueConstraintViolationException::class);
1602
1603
        $boatDao->save($boatBean);
1604
    }
1605
1606
    /**
1607
     * @depends testSaveTransaction
1608
     */
1609
    public function testSaveTransaction2()
1610
    {
1611
        $boatDao = new BoatDao($this->tdbmService);
1612
        $boatBean = $boatDao->getById(1);
1613
1614
        // The name should not have been saved because the transaction of the previous test should have rollbacked.
1615
        $this->assertNotSame('Bismark', $boatBean->getName());
1616
    }
1617
1618
    /**
1619
     * @depends testDaoGeneration
1620
     */
1621
    public function testForeignKeyPointingToNonPrimaryKey()
1622
    {
1623
        $dao = new RefNoPrimKeyDao($this->tdbmService);
1624
        $bean = $dao->getById(1);
1625
1626
        $this->assertSame('foo', $bean->getFrom()->getTo());
1627
1628
        $newBean = new RefNoPrimKeyBean($bean, 'baz');
1629
        $dao->save($newBean);
1630
        $this->assertSame('foo', $newBean->getFrom()->getTo());
1631
1632
        $resultSet = $bean->getRefNoPrimKey();
1633
        $this->assertCount(2, $resultSet);
1634
    }
1635
1636
    /**
1637
     * @depends testDaoGeneration
1638
     */
1639
    public function testCloningUuidBean()
1640
    {
1641
        $article = new ArticleBean('content');
1642
        $this->assertNotEmpty($article->getId());
1643
        $article2 = clone $article;
1644
        $this->assertNotEmpty($article2->getId());
1645
        $this->assertNotSame($article->getId(), $article2->getId());
1646
    }
1647
1648
    /**
1649
     * @depends testDaoGeneration
1650
     */
1651
    public function testRecursiveSave()
1652
    {
1653
        $categoryDao = new CategoryDao($this->tdbmService);
1654
1655
        $root1 = new CategoryBean('Root1');
1656
        $categoryDao->save($root1);
1657
        // Root 2 is not saved yet.
1658
        $root2 = new CategoryBean('Root2');
1659
        $intermediate = new CategoryBean('Intermediate');
1660
        $categoryDao->save($intermediate);
1661
1662
        // Let's switch the parent to a bean in detached state.
1663
        $intermediate->setParent($root2);
1664
1665
        // Now, let's save a new category that references the leaf category.
1666
        $leaf = new CategoryBean('Leaf');
1667
        $leaf->setParent($intermediate);
1668
        $categoryDao->save($leaf);
1669
        $this->assertNull($root2->getId());
1670
    }
1671
1672
    /**
1673
     * @depends testDaoGeneration
1674
     */
1675
    public function testBlob()
1676
    {
1677
        $fp = fopen(__FILE__, 'r');
1678
        $file = new FileBean($fp);
1679
1680
        $fileDao = new FileDao($this->tdbmService);
1681
1682
        $fileDao->save($file);
1683
1684
        $loadedFile = $fileDao->getById($file->getId());
1685
1686
        $resource = $loadedFile->getFile();
1687
        $result = fseek($resource, 0);
1688
        $this->assertSame(0, $result);
1689
        $this->assertInternalType('resource', $resource);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1689
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('resource', $resource);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1690
        $firstLine = fgets($resource);
1691
        $this->assertSame("<?php\n", $firstLine);
1692
    }
1693
1694
    /**
1695
     * @depends testBlob
1696
     */
1697
    public function testReadBlob()
1698
    {
1699
        $fileDao = new FileDao($this->tdbmService);
1700
        $loadedFile = $fileDao->getById(1);
1701
1702
        $resource = $loadedFile->getFile();
1703
        $this->assertInternalType('resource', $resource);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit\Framework\Assert::assertInternalType() has been deprecated: https://github.com/sebastianbergmann/phpunit/issues/3369 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

1703
        /** @scrutinizer ignore-deprecated */ $this->assertInternalType('resource', $resource);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
1704
        $firstLine = fgets($resource);
1705
        $this->assertSame("<?php\n", $firstLine);
1706
1707
        stream_get_contents($resource);
1708
1709
        $loadedFile->setId($loadedFile->getId());
1710
1711
        $fileDao->save($loadedFile);
1712
    }
1713
1714
    /**
1715
     * @depends testReadBlob
1716
     */
1717
    public function testReadAndSaveBlob()
1718
    {
1719
        $fileDao = new FileDao($this->tdbmService);
1720
        $loadedFile = $fileDao->getById(1);
1721
1722
        $resource = $loadedFile->getFile();
1723
1724
        $firstLine = fgets($resource);
1725
        $this->assertSame("<?php\n", $firstLine);
1726
    }
1727
1728
    /**
1729
     * @depends testReadBlob
1730
     */
1731
    public function testProtectedGetterSetter()
1732
    {
1733
        $md5Getter = new ReflectionMethod(FileBaseBean::class, 'getMd5');
1734
        $md5Setter = new ReflectionMethod(FileBaseBean::class, 'setMd5');
1735
1736
        $this->assertTrue($md5Getter->isProtected());
1737
        $this->assertTrue($md5Setter->isProtected());
1738
1739
        $md5Getter2 = new ReflectionMethod(FileBaseBean::class, 'getArticle');
1740
        $md5Setter2 = new ReflectionMethod(FileBaseBean::class, 'setArticle');
1741
1742
        $this->assertTrue($md5Getter2->isProtected());
1743
        $this->assertTrue($md5Setter2->isProtected());
1744
1745
        $oneToManyGetter = new ReflectionMethod(ArticleBaseBean::class, 'getFiles');
1746
        $this->assertTrue($oneToManyGetter->isProtected());
1747
1748
        $fileDao = new FileDao($this->tdbmService);
1749
        $loadedFile = $fileDao->getById(1);
1750
1751
        // The md5 and article columns are not JSON serialized
1752
        $this->assertSame([
1753
            'id' => 1,
1754
        ], $loadedFile->jsonSerialize());
1755
    }
1756
1757
    /**
1758
     * @depends testDaoGeneration
1759
     */
1760
    public function testBlobResourceException()
1761
    {
1762
        $this->expectException(TDBMInvalidArgumentException::class);
1763
        $this->expectExceptionMessage('Invalid argument passed to \'TheCodingMachine\\TDBM\\Test\\Dao\\Bean\\Generated\\FileBaseBean::setFile\'. Expecting a resource. Got a string.');
1764
        new FileBean('foobar');
1765
    }
1766
1767
    /**
1768
     * @depends testDaoGeneration
1769
     */
1770
    public function testFilterBag()
1771
    {
1772
        $userDao = new TestUserDao($this->tdbmService);
1773
        $countryDao = new CountryDao($this->tdbmService);
1774
1775
        $country = $countryDao->getById(2);
1776
1777
        // Let's test filter bags by bean and filter bag with many values.
1778
        $users = $userDao->getUsersByComplexFilterBag($country, ['John Doe', 'Jane Doe']);
1779
1780
        $this->assertCount(1, $users);
1781
        $this->assertSame('John Doe', $users[0]->getName());
1782
    }
1783
1784
    /**
1785
     * @depends testDaoGeneration
1786
     */
1787
    public function testDecimalIsMappedToString()
1788
    {
1789
        $reflectionClass = new \ReflectionClass(BoatBaseBean::class);
1790
        $this->assertSame('string', (string) $reflectionClass->getMethod('getLength')->getReturnType());
1791
    }
1792
1793
    /**
1794
     * @depends testDaoGeneration
1795
     */
1796
    public function testNoGetByIdOnMultiPrimaryKeys()
1797
    {
1798
        $reflectionClass = new \ReflectionClass(StateDao::class);
1799
        $this->assertFalse($reflectionClass->hasMethod('getById'));
1800
    }
1801
1802
    /**
1803
     * @depends testDaoGeneration
1804
     */
1805
    public function testInsertMultiPrimaryKeysBean()
1806
    {
1807
        $countryDao = new CountryDao($this->tdbmService);
1808
1809
        $country = $countryDao->getById(1);
1810
1811
        $stateDao = new StateDao($this->tdbmService);
1812
        $state = new StateBean($country, 'IDF', 'Ile de France');
1813
        $stateDao->save($state);
1814
1815
        $this->assertSame($state, $stateDao->findAll()[0]);
1816
    }
1817
1818
    /**
1819
     * @depends testInsertMultiPrimaryKeysBean
1820
     */
1821
    public function testDeleteMultiPrimaryKeysBean()
1822
    {
1823
        $stateDao = new StateDao($this->tdbmService);
1824
1825
        $state = $stateDao->findAll()[0];
1826
        $stateDao->delete($state);
1827
        $this->assertCount(0, $stateDao->findAll());
1828
1829
    }
1830
1831
    /**
1832
     * @depends testDaoGeneration
1833
     */
1834
    public function testSortOnInheritedTable()
1835
    {
1836
        $animalDao = new AnimalDao($this->tdbmService);
1837
1838
        // Let's insert an animal that is nothing.
1839
        $animal = new AnimalBean('Mickey');
1840
        $animalDao->save($animal);
1841
1842
        $animals = $animalDao->findAll()->withOrder('dog.race ASC');
1843
1844
        $animalsArr = $animals->toArray();
1845
        $this->assertCount(3, $animalsArr);
1846
    }
1847
1848
    /**
1849
     * @depends testDaoGeneration
1850
     */
1851
    public function testJsonKey()
1852
    {
1853
        $node = new NodeBean('foo.html');
1854
        $json = $node->jsonSerialize();
1855
        self::assertTrue(isset($json['basename']));
1856
        self::assertEquals('foo.html', $json['basename']);
1857
    }
1858
1859
    /**
1860
     * @depends testDaoGeneration
1861
     */
1862
    public function testJsonIgnore()
1863
    {
1864
        $nodeDao = new NodeDao($this->tdbmService);
1865
        $index = $nodeDao->getById(6);
1866
        $json = $index->jsonSerialize();
1867
        // Ignored scalar 'id'
1868
        self::assertTrue(!isset($json['id']));
1869
        // Ignored object 'root'
1870
        self::assertTrue(!isset($json['root']));
1871
        self::assertTrue(isset($json['guests']));
1872
        self::assertTrue(!empty($json['guests']));
1873
        $account = $index->getAccounts()[0];
1874
        $json = $account->jsonSerialize();
1875
        // Ignored array 'nodes' (from nodes_users table)
1876
        self::assertTrue(!isset($json['nodes']));
1877
    }
1878
1879
    /**
1880
     * @depends testDaoGeneration
1881
     */
1882
    public function testJsonInclude()
1883
    {
1884
        $nodeDao = new NodeDao($this->tdbmService);
1885
        $index = $nodeDao->getById(6);
1886
        $json = $index->jsonSerialize();
1887
        // Whole chain of parents should be serialized
1888
        self::assertTrue(isset($json['parent']));
1889
        self::assertTrue(isset($json['parent']['parent']));
1890
        self::assertTrue(isset($json['parent']['parent']['parent']));
1891
        self::assertEquals('/', $json['parent']['parent']['parent']['basename']);
1892
    }
1893
1894
    /**
1895
     * @depends testDaoGeneration
1896
     */
1897
    public function testJsonRecursive()
1898
    {
1899
        $nodeDao = new NodeDao($this->tdbmService);
1900
        $index = $nodeDao->getById(8);
1901
        $json = $index->jsonSerialize();
1902
        // Original chain of aliases is recursively serialized, ...
1903
        self::assertTrue(isset($json['alias']));
1904
        self::assertTrue(isset($json['alias']['alias']));
1905
        self::assertEquals('index.html', $json['alias']['alias']['basename']);
1906
        // ... each alias even serializes its parents, ...
1907
        self::assertTrue(isset($json['alias']['alias']['parent']['parent']));
1908
        // ... however, parents aliases chains are not serialized, as parents are serialized with $stopRecursion=true
1909
        self::assertTrue(!isset($json['alias']['alias']['parent']['parent']['alias']));
1910
        self::assertNotNull($index->getAlias()->getAlias()->getParent()->getParent()->getAlias());
1911
    }
1912
1913
    /**
1914
     * @depends testDaoGeneration
1915
     */
1916
    public function testJsonFormat()
1917
    {
1918
        $nodeDao = new NodeDao($this->tdbmService);
1919
        $index = $nodeDao->getById(6);
1920
        $json = $index->jsonSerialize();
1921
        self::assertTrue(isset($json['size']));
1922
        self::assertEquals('512 o', $json['size']);
1923
        self::assertEquals('42.50g', $json['weight']);
1924
        self::assertEquals($index->getCreatedAt()->format('Y-m-d'), $json['createdAt']);
1925
        self::assertEquals($index->getOwner()->getName(), $json['owner']);
1926
        self::assertEquals($index->getAccounts()[1]->getName(), $json['guests'][1]);
1927
        self::assertTrue(isset($json['entries']));
1928
        self::assertEquals('Hello, World', $json['entries'][1]);
1929
        $www = $index->getParent();
1930
        $json = $www->jsonSerialize();
1931
        self::assertEquals('0 o', $json['size']);
1932
        self::assertNull($json['weight']);
1933
        self::assertNull($json['owner']);
1934
    }
1935
1936
    /**
1937
     * @depends testDaoGeneration
1938
     */
1939
    public function testJsonCollection()
1940
    {
1941
        $artists = new ArtistDao($this->tdbmService);
1942
        $pinkFloyd = $artists->getById(1);
1943
        $animals =  $pinkFloyd->getAlbums()[0];
1944
        $json = $pinkFloyd->jsonSerialize();
1945
        // Collection name properly handled ('discography' instead of default 'albums')
1946
        self::assertTrue(isset($json['discography']));
1947
        self::assertEquals($animals->getTitle(), $json['discography'][0]['title']);
1948
        // Make sure top object is not its own grandfather
1949
        self::assertTrue(!isset($json['discography'][0]['artist']));
1950
        $json = $animals->jsonSerialize();
1951
        // Nevertheless, artist should be serialized in album as top object...
1952
        self::assertTrue(isset($json['artist']));
1953
        // ... as should be tracks...
1954
        self::assertTrue(isset($json['tracks'][0]));
1955
        self::assertEquals('Pigs on the Wing 1', $json['tracks'][0]['title']);
1956
        // ... and, ultimately, list of featuring artists, since feat is included
1957
        self::assertTrue(isset($json['tracks'][0]['feat'][0]));
1958
        self::assertEquals('Roger Waters', $json['tracks'][0]['feat'][0]['name']);
1959
    }
1960
1961
    /**
1962
     * @depends testDaoGeneration
1963
     */
1964
    public function testAddInterfaceAnnotation()
1965
    {
1966
        $refClass = new ReflectionClass(UserBaseBean::class);
1967
        $this->assertTrue($refClass->implementsInterface(TestUserInterface::class));
1968
    }
1969
1970
    /**
1971
     * @depends testDaoGeneration
1972
     */
1973
    public function testAddInterfaceOnDaoAnnotation()
1974
    {
1975
        $refClass = new ReflectionClass(UserBaseDao::class);
1976
        $this->assertTrue($refClass->implementsInterface(TestUserDaoInterface::class));
1977
    }
1978
1979
    public function testTrait()
1980
    {
1981
        $userDao = new UserDao($this->tdbmService);
1982
        $userBean = $userDao->getById(1);
1983
1984
        $this->assertSame('TestOtherUserTrait', $userBean->method1());
1985
        $this->assertSame('TestUserTrait', $userBean->method1renamed());
1986
1987
        $refClass = new ReflectionClass(UserBaseDao::class);
1988
        $this->assertTrue($refClass->hasMethod('findNothing'));
1989
    }
1990
}
1991