ModelProviderTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 62
dl 0
loc 114
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetManufacturers() 0 32 1
A setUp() 0 37 1
1
<?php
2
/**
3
 * File: ModelProviderTest.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\Otomoto\App\Test\Unit\Model;
10
11
use MSlwk\Otomoto\App\Base\UrlProvider;
12
use MSlwk\Otomoto\App\Manufacturer\Data\ManufacturerDTO;
13
use MSlwk\Otomoto\App\Model\Data\ModelDTO;
14
use MSlwk\Otomoto\App\Model\Data\ModelDTOArray;
15
use MSlwk\Otomoto\App\Model\ModelProvider;
16
use MSlwk\Otomoto\App\Model\Scrapper\ModelHtmlScrapper;
17
use MSlwk\Otomoto\App\Model\Validator\ModelsScrappedValidator;
18
use MSlwk\Otomoto\Middleware\Webpage\Adapter\ReactPHP\ReactPHPRequestAdapter;
19
use MSlwk\Otomoto\Middleware\Webpage\Data\WebpageDTO;
20
use MSlwk\Otomoto\Middleware\Webpage\Data\WebpageDTOArray;
21
use MSlwk\Otomoto\Middleware\Webpage\Factory\ReactPHP\ReactPHPAdapterFactory;
22
use PHPUnit\Framework\MockObject\MockObject;
23
use PHPUnit\Framework\TestCase;
24
use MSlwk\Otomoto\App\Manufacturer\Url\ManufacturerUrlSuffixProvider;
25
26
/**
27
 * Class ModelProviderTest
28
 * @package MSlwk\Otomoto\App\Test\Unit\Model
29
 */
30
class ModelProviderTest extends TestCase
31
{
32
    /**
33
     * @var MockObject|ReactPHPAdapterFactory
34
     */
35
    private $adapterFactory;
36
37
    /**
38
     * @var MockObject|UrlProvider
39
     */
40
    private $urlPovider;
41
42
    /**
43
     * @var MockObject|ModelHtmlScrapper
44
     */
45
    private $modelHtmlScrapper;
46
47
    /**
48
     * @var MockObject|ModelsScrappedValidator
49
     */
50
    private $modelsScrappedValidator;
51
52
    /**
53
     * @var MockObject|ManufacturerUrlSuffixProvider
54
     */
55
    private $manufacturerUrlSuffixProvider;
56
57
    /**
58
     * @var MockObject|ModelProvider
59
     */
60
    private $modelProvider;
61
62
    /**
63
     * @var MockObject|ReactPHPRequestAdapter
64
     */
65
    private $GETAdapter;
66
67
    /**
68
     * @retun void
69
     */
70
    protected function setUp()
71
    {
72
        $this->adapterFactory = $this->getMockBuilder(ReactPHPAdapterFactory::class)
73
            ->disableOriginalConstructor()
74
            ->getMock();
75
        $this->urlPovider = $this->getMockBuilder(UrlProvider::class)
76
            ->disableOriginalConstructor()
77
            ->getMock();
78
        $this->modelHtmlScrapper = $this->getMockBuilder(ModelHtmlScrapper::class)
79
            ->disableOriginalConstructor()
80
            ->getMock();
81
        $this->modelsScrappedValidator = $this->getMockBuilder(ModelsScrappedValidator::class)
82
            ->disableOriginalConstructor()
83
            ->getMock();
84
        $this->manufacturerUrlSuffixProvider = $this->getMockBuilder(ManufacturerUrlSuffixProvider::class)
85
            ->disableOriginalConstructor()
86
            ->getMock();
87
        $this->modelProvider = $this->getMockBuilder(ModelProvider::class)
88
            ->setConstructorArgs(
89
                [
90
                    $this->adapterFactory,
91
                    $this->urlPovider,
92
                    $this->modelHtmlScrapper,
93
                    $this->modelsScrappedValidator,
94
                    $this->manufacturerUrlSuffixProvider
95
                ]
96
            )
97
            ->setMethods(null)
98
            ->getMock();
99
100
        $this->GETAdapter = $this->getMockBuilder(ReactPHPRequestAdapter::class)
101
            ->disableOriginalConstructor()
102
            ->getMock();
103
104
        $this->adapterFactory->expects($this->once())
105
            ->method('create')
106
            ->will($this->returnValue($this->GETAdapter));
107
    }
108
109
    /**
110
     * @test
111
     */
112
    public function testGetManufacturers()
113
    {
114
        $model1 = new ModelDTO('model1');
115
        $model2 = new ModelDTO('model2');
116
        $model3 = new ModelDTO('model3');
117
        $modelDTOArray = new ModelDTOArray($model1, $model2, $model3);
118
        $manufacturer = new ManufacturerDTO('manufacturer');
119
120
        $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

120
        $this->urlPovider->/** @scrutinizer ignore-call */ 
121
                           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...
121
            ->method('getBaseUrl')
122
            ->will($this->returnValue('url'));
123
        $this->manufacturerUrlSuffixProvider->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Manufa...cturerUrlSuffixProvider. ( Ignorable by Annotation )

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

123
        $this->manufacturerUrlSuffixProvider->/** @scrutinizer ignore-call */ 
124
                                              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...
124
            ->method('getUrlSuffix')
125
            ->with($manufacturer);
126
        $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

126
        $this->GETAdapter->/** @scrutinizer ignore-call */ 
127
                           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...
127
            ->method('getWebpages')
128
            ->will($this->returnValue(new WebpageDTOArray(new WebpageDTO('html'))));
129
130
        $this->modelHtmlScrapper->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Model\Scrapper\ModelHtmlScrapper. ( Ignorable by Annotation )

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

130
        $this->modelHtmlScrapper->/** @scrutinizer ignore-call */ 
131
                                  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...
131
            ->method('scrapModels')
132
            ->will($this->returnValue($modelDTOArray));
133
134
        $this->modelsScrappedValidator->expects($this->once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on MSlwk\Otomoto\App\Model\...ModelsScrappedValidator. ( Ignorable by Annotation )

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

134
        $this->modelsScrappedValidator->/** @scrutinizer ignore-call */ 
135
                                        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...
135
            ->method('validate')
136
            ->with($modelDTOArray);
137
138
        /** @var ModelDTOArray $returnedModels */
139
        $returnedModels = $this->modelProvider->getModels($manufacturer);
0 ignored issues
show
Bug introduced by
The method getModels() 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

139
        /** @scrutinizer ignore-call */ 
140
        $returnedModels = $this->modelProvider->getModels($manufacturer);

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...
140
141
        $this->assertInstanceOf(ModelDTOArray::class, $returnedModels);
142
        $this->assertEquals($model1->getName(), $returnedModels->current()->getName());
143
        $this->assertEquals($model3->getName(), $returnedModels->get(2)->getName());
144
    }
145
}
146