Failed Conditions
Pull Request — master (#7468)
by Caio
11:25
created

DDC3740Test::testCountIsCachedEvenWithZeroResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\ORM\LazyCriteriaCollection;
8
use Doctrine\Tests\Models\Tweet\Tweet;
9
use Doctrine\Tests\Models\Tweet\User;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Doctrine\Tests\ORM\Functional\Ticket\User. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use Doctrine\Tests\OrmFunctionalTestCase;
11
use Doctrine\Common\Collections\Criteria;
0 ignored issues
show
Coding Style introduced by
Use statements should be sorted alphabetically. The first wrong one is Doctrine\Common\Collections\Criteria.
Loading history...
12
13
class DDC3740Test extends OrmFunctionalTestCase
14
{
15
    /** @var Criteria */
16
    private $criteria;
17
18
    /** @var LazyCriteriaCollection */
19
    private $lazyCriteriaCollection;
20
21
    protected function setUp(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
22
    {
23
        $this->useModelSet('tweet');
24
        parent::setUp();
25
26
        $this->criteria = new Criteria();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
27
        $this->lazyCriteriaCollection = new LazyCriteriaCollection(
28
            $this->em->getUnitOfWork()->getEntityPersister(Tweet::class),
29
            $this->criteria
30
        );
31
    }
32
33
    public function testCountIsCached() : void
34
    {
35
        $user  = new User();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 2 spaces

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
        $user->name = "Caio";
37
38
        $tweet = new Tweet();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
39
        $tweet->content = 'I am a teapot!';
40
41
        $user->addTweet($tweet);
42
43
        $this->em->persist($user);
44
        $this->em->persist($tweet);
45
        $this->em->flush();
46
        $this->em->clear();
47
48
        self::assertSame(1, $this->lazyCriteriaCollection->count());
49
        self::assertSame(1, $this->lazyCriteriaCollection->count());
50
        self::assertSame(1, $this->lazyCriteriaCollection->count());
51
    }
52
53
    public function testCountIsCachedEvenWithZeroResult() : void
54
    {
55
        self::assertSame(0, $this->lazyCriteriaCollection->count());
56
        self::assertSame(0, $this->lazyCriteriaCollection->count());
57
        self::assertSame(0, $this->lazyCriteriaCollection->count());
58
    }
59
}
60