ManufacturerProviderTest::testGetManufacturers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 28
rs 9.6
c 0
b 0
f 0
1
<?php
2
/**
3
 * File: ManufacturerProviderTest.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\Otomoto\App\Test\Unit\Manufacturer;
10
11
use MSlwk\Otomoto\App\Base\UrlProvider;
12
use MSlwk\Otomoto\App\Manufacturer\Data\ManufacturerDTO;
13
use MSlwk\Otomoto\App\Manufacturer\Data\ManufacturerDTOArray;
14
use MSlwk\Otomoto\App\Manufacturer\ManufacturerProvider;
15
use MSlwk\Otomoto\App\Manufacturer\Scrapper\ManufacturerHtmlScrapper;
16
use MSlwk\Otomoto\App\Manufacturer\Validator\ManufacturersScrappedValidator;
17
use MSlwk\Otomoto\Middleware\Webpage\Adapter\ReactPHP\ReactPHPRequestAdapter;
18
use MSlwk\Otomoto\Middleware\Webpage\Data\WebpageDTO;
19
use MSlwk\Otomoto\Middleware\Webpage\Data\WebpageDTOArray;
20
use MSlwk\Otomoto\Middleware\Webpage\Factory\ReactPHP\ReactPHPAdapterFactory;
21
use PHPUnit\Framework\MockObject\MockObject;
22
use PHPUnit\Framework\TestCase;
23
24
/**
25
 * Class ManufacturerProviderTest
26
 * @package MSlwk\Otomoto\App\Test\Unit\Manufacturer
27
 */
28
class ManufacturerProviderTest extends TestCase
29
{
30
    /**
31
     * @var MockObject|ReactPHPAdapterFactory
32
     */
33
    private $adapterFactory;
34
35
    /**
36
     * @var MockObject|UrlProvider
37
     */
38
    private $urlPovider;
39
40
    /**
41
     * @var MockObject|ManufacturerHtmlScrapper
42
     */
43
    private $manufacturerHtmlScrapper;
44
45
    /**
46
     * @var MockObject|ManufacturersScrappedValidator
47
     */
48
    private $manufacturersScrappedValidator;
49
50
    /**
51
     * @var MockObject|ManufacturerProvider
52
     */
53
    private $manufacturerProvider;
54
55
    /**
56
     * @var MockObject|ReactPHPRequestAdapter
57
     */
58
    private $GETAdapter;
59
60
    /**
61
     * @retun void
62
     */
63
    protected function setUp()
64
    {
65
        $this->adapterFactory = $this->getMockBuilder(ReactPHPAdapterFactory::class)
66
            ->disableOriginalConstructor()
67
            ->getMock();
68
        $this->urlPovider = $this->getMockBuilder(UrlProvider::class)
69
            ->disableOriginalConstructor()
70
            ->getMock();
71
        $this->manufacturerHtmlScrapper = $this->getMockBuilder(ManufacturerHtmlScrapper::class)
72
            ->disableOriginalConstructor()
73
            ->getMock();
74
        $this->manufacturersScrappedValidator = $this->getMockBuilder(ManufacturersScrappedValidator::class)
75
            ->disableOriginalConstructor()
76
            ->getMock();
77
        $this->manufacturerProvider = $this->getMockBuilder(ManufacturerProvider::class)
78
            ->setConstructorArgs(
79
                [
80
                    $this->adapterFactory,
81
                    $this->urlPovider,
82
                    $this->manufacturerHtmlScrapper,
83
                    $this->manufacturersScrappedValidator
84
                ]
85
            )->setMethods(null)
86
            ->getMock();
87
88
        $this->GETAdapter = $this->getMockBuilder(ReactPHPRequestAdapter::class)
89
            ->disableOriginalConstructor()
90
            ->getMock();
91
92
        $this->adapterFactory->expects($this->once())
93
            ->method('create')
94
            ->will($this->returnValue($this->GETAdapter));
95
    }
96
97
    /**
98
     * @test
99
     */
100
    public function testGetManufacturers()
101
    {
102
        $manufacturer1 = new ManufacturerDTO('manufacturer1');
103
        $manufacturer2 = new ManufacturerDTO('manufacturer2');
104
        $manufacturer3 = new ManufacturerDTO('manufacturer3');
105
        $manufacturerDTOArray = new ManufacturerDTOArray($manufacturer1, $manufacturer2, $manufacturer3);
106
107
        $this->urlPovider->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Base\UrlProvider. ( Ignorable by Annotation )

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

107
        $this->urlPovider->/** @scrutinizer ignore-call */ 
108
                           expects($this->once())

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...
108
            ->method('getBaseUrl')
109
            ->will($this->returnValue('url'));
110
        $this->GETAdapter->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\Middleware...\ReactPHPRequestAdapter. ( Ignorable by Annotation )

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

110
        $this->GETAdapter->/** @scrutinizer ignore-call */ 
111
                           expects($this->once())

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...
111
            ->method('getWebpages')
112
            ->will($this->returnValue(new WebpageDTOArray(new WebpageDTO('html'))));
113
114
        $this->manufacturerHtmlScrapper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Manufa...anufacturerHtmlScrapper. ( Ignorable by Annotation )

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

114
        $this->manufacturerHtmlScrapper->/** @scrutinizer ignore-call */ 
115
                                         expects($this->once())

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...
115
            ->method('scrapManufacturers')
116
            ->will($this->returnValue($manufacturerDTOArray));
117
118
        $this->manufacturersScrappedValidator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Manufa...turersScrappedValidator. ( Ignorable by Annotation )

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

118
        $this->manufacturersScrappedValidator->/** @scrutinizer ignore-call */ 
119
                                               expects($this->once())

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...
119
            ->method('validate')
120
            ->with($manufacturerDTOArray);
121
122
        /** @var ManufacturerDTOArray $returnedManufacturers */
123
        $returnedManufacturers = $this->manufacturerProvider->getManufacturers();
0 ignored issues
show
Bug introduced by
The method getManufacturers() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

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

123
        /** @scrutinizer ignore-call */ 
124
        $returnedManufacturers = $this->manufacturerProvider->getManufacturers();

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...
124
125
        $this->assertInstanceOf(ManufacturerDTOArray::class, $returnedManufacturers);
126
        $this->assertEquals($manufacturer1->getName(), $returnedManufacturers->current()->getName());
127
        $this->assertEquals($manufacturer3->getName(), $returnedManufacturers->get(2)->getName());
128
    }
129
}
130