Completed
Push — master ( e0017c...6b1304 )
by Tom
14s queued 11s
created

Validator/NoObjectExistsTest.php (13 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModuleTest\Validator\Adapter;
6
7
use DoctrineModule\Validator\NoObjectExists;
8
use PHPUnit\Framework\TestCase as BaseTestCase;
9
use stdClass;
10
use function str_replace;
11
12
/**
13
 * Tests for the NoObjectExists tests
14
 *
15
 * @link    http://www.doctrine-project.org/
16
 */
17
class NoObjectExistsTest extends BaseTestCase
18
{
19
    public function testCanValidateWithNoAvailableObjectInRepository() : void
20
    {
21
        $repository = $this->createMock('Doctrine\Persistence\ObjectRepository');
0 ignored issues
show
Are you sure the assignment to $repository is correct as $this->createMock('Doctr...nce\\ObjectRepository') (which targets PHPUnit\Framework\TestCase::createMock()) 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...
22
23
        $repository
0 ignored issues
show
The method expects cannot be called on $repository (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
24
            ->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
            ->method('findOneBy')
26
            ->will($this->returnValue(null));
27
28
        $validator = new NoObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']);
29
30
        $this->assertTrue($validator->isValid('matchValue'));
31
    }
32
33
    public function testCannotValidateWithAvailableObjectInRepository() : void
34
    {
35
        $repository = $this->createMock('Doctrine\Persistence\ObjectRepository');
0 ignored issues
show
Are you sure the assignment to $repository is correct as $this->createMock('Doctr...nce\\ObjectRepository') (which targets PHPUnit\Framework\TestCase::createMock()) 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...
36
37
        $repository
0 ignored issues
show
The method expects cannot be called on $repository (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
38
            ->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
            ->method('findOneBy')
40
            ->will($this->returnValue(new stdClass()));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
42
        $validator = new NoObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']);
43
44
        $this->assertFalse($validator->isValid('matchValue'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
    }
46
47
    public function testErrorMessageIsStringInsteadArray() : void
48
    {
49
        $repository = $this->createMock('Doctrine\Persistence\ObjectRepository');
0 ignored issues
show
Are you sure the assignment to $repository is correct as $this->createMock('Doctr...nce\\ObjectRepository') (which targets PHPUnit\Framework\TestCase::createMock()) 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...
50
        $repository
0 ignored issues
show
The method expects cannot be called on $repository (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
51
            ->expects($this->once())
0 ignored issues
show
The method once() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
            ->method('findOneBy')
53
            ->will($this->returnValue(new stdClass()));
0 ignored issues
show
The method returnValue() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $validator = new NoObjectExists(['object_repository' => $repository, 'fields' => 'matchKey']);
55
56
        $this->assertFalse($validator->isValid('matchValue'));
0 ignored issues
show
The method assertFalse() does not seem to exist on object<DoctrineModuleTes...ter\NoObjectExistsTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
57
58
        $messageTemplates = $validator->getMessageTemplates();
59
60
        $expectedMessage = str_replace(
61
            '%value%',
62
            'matchValue',
63
            $messageTemplates[NoObjectExists::ERROR_OBJECT_FOUND]
64
        );
65
        $messages        = $validator->getMessages();
66
        $receivedMessage = $messages[NoObjectExists::ERROR_OBJECT_FOUND];
67
68
        $this->assertSame($expectedMessage, $receivedMessage);
69
    }
70
}
71