testLicenseeActionWithNoLicensees()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/* Copyright (C) 2017 Michael Giesler
3
 *
4
 * This file is part of Dembelo.
5
 *
6
 * Dembelo is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Affero General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * Dembelo is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Affero General Public License 3 for more details.
15
 *
16
 * You should have received a copy of the GNU Affero General Public License 3
17
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace AdminBundle\Tests\Controller;
21
22
use AdminBundle\Controller\LicenseeController;
23
use DembeloMain\Document\Licensee;
24
use DembeloMain\Model\Repository\Doctrine\ODM\LicenseeRepository;
25
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
26
use Symfony\Component\HttpFoundation\Response;
27
28
/**
29
 * Class LicenseeControllerTest
30
 */
31
class LicenseeControllerTest extends WebTestCase
32
{
33
    /**
34
     * @var LicenseeController
35
     */
36
    private $controller;
37
38
    /**
39
     * @var \PHPUnit_Framework_MockObject_MockObject|LicenseeRepository
40
     */
41
    private $licenseeRepositoryMock;
42
43
    /**
44
     * @return void
45
     */
46
    protected function setUp(): void
47
    {
48
        $this->licenseeRepositoryMock = $this->createLicenseeRepositoryMock();
49
50
        $this->controller = new LicenseeController($this->licenseeRepositoryMock);
51
    }
52
53
    /**
54
     * tests licenseeAction with no licensees
55
     * @return void
56
     */
57
    public function testLicenseeActionWithNoLicensees(): void
58
    {
59
        $this->licenseeRepositoryMock->expects($this->once())
0 ignored issues
show
Deprecated Code introduced by
The function DembeloMain\Model\Reposi...seeRepository::__call() has been deprecated: method was deprecated in 1.2 and will be removed in 2.0 ( Ignorable by Annotation )

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

59
        /** @scrutinizer ignore-deprecated */ $this->licenseeRepositoryMock->expects($this->once())

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...
Bug introduced by
The method expects() does not exist on DembeloMain\Model\Reposi...\ODM\LicenseeRepository. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

59
        $this->licenseeRepositoryMock->/** @scrutinizer ignore-call */ 
60
                                       expects($this->once())
Loading history...
60
            ->method('findAll')
61
            ->willReturn([]);
62
63
        /* @var $response \Symfony\Component\HttpFoundation\Response */
64
        $response = $this->controller->licenseesAction();
65
        $this->assertInstanceOf(Response::class, $response);
66
        $this->assertJsonStringEqualsJsonString('[]', $response->getContent());
67
        $this->assertEquals('200', $response->getStatusCode());
68
    }
69
70
    /**
71
     * tests licenseeAction() with one licensee
72
     * @return void
73
     */
74
    public function testLicenseeActionWithOneLicensee(): void
75
    {
76
        $licensee = new Licensee();
77
        $licensee->setName('someName');
78
        $licensee->setId('someId');
79
80
        $this->licenseeRepositoryMock->expects($this->once())
0 ignored issues
show
Deprecated Code introduced by
The function DembeloMain\Model\Reposi...seeRepository::__call() has been deprecated: method was deprecated in 1.2 and will be removed in 2.0 ( Ignorable by Annotation )

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

80
        /** @scrutinizer ignore-deprecated */ $this->licenseeRepositoryMock->expects($this->once())

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...
81
            ->method('findAll')
82
            ->willReturn([$licensee]);
83
84
        /* @var $response \Symfony\Component\HttpFoundation\Response */
85
        $response = $this->controller->licenseesAction();
86
        $this->assertInstanceOf(Response::class, $response);
87
        $this->assertJsonStringEqualsJsonString('[{"id":"someId","name":"someName"}]', $response->getContent());
88
        $this->assertEquals('200', $response->getStatusCode());
89
    }
90
91
    /**
92
     * @return \PHPUnit_Framework_MockObject_MockObject|LicenseeRepository
93
     */
94
    private function createLicenseeRepositoryMock(): LicenseeRepository
95
    {
96
        $repository = $this->getMockBuilder(LicenseeRepository::class)
97
            ->disableOriginalConstructor()
98
            ->setMethods(['findAll', 'save', 'find', 'findBy', 'findOneBy', 'getClassName', 'findOneByName'])
99
            ->getMock();
100
101
        return $repository;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $repository returns the type PHPUnit\Framework\MockObject\MockObject which is incompatible with the type-hinted return DembeloMain\Model\Reposi...\ODM\LicenseeRepository.
Loading history...
102
    }
103
}
104