8
8
9
9
namespace Magento \Fedex \Test \Unit \Model \Config \Backend ;
10
10
11
+ use Magento \Fedex \Model \Config \Backend \FedexUrl ;
12
+ use Magento \Framework \App \Cache \TypeListInterface ;
13
+ use Magento \Framework \App \Config \ScopeConfigInterface ;
14
+ use Magento \Framework \Data \Collection \AbstractDb ;
15
+ use Magento \Framework \Event \ManagerInterface ;
11
16
use Magento \Framework \Exception \ValidatorException ;
17
+ use Magento \Framework \Model \Context ;
18
+ use Magento \Framework \Registry ;
12
19
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
13
- use Magento \Fedex \Model \Config \Backend \FedexUrl ;
20
+ use Magento \Framework \Validator \Url ;
21
+ use Magento \Rule \Model \ResourceModel \AbstractResource ;
22
+ use PHPUnit \Framework \MockObject \MockObject ;
14
23
use PHPUnit \Framework \TestCase ;
15
24
16
25
/**
@@ -22,39 +31,70 @@ class FedexUrlTest extends TestCase
22
31
/**
23
32
* @var FedexUrl
24
33
*/
25
- private $ config ;
34
+ private $ urlConfig ;
26
35
27
36
/**
28
- * @return void
37
+ * @var Url
29
38
*/
39
+ private $ url ;
40
+
41
+ /**
42
+ * @var Context|MockObject
43
+ */
44
+ private $ contextMock ;
45
+
30
46
protected function setUp (): void
31
47
{
32
48
$ objectManager = new ObjectManager ($ this );
33
- /** @var FedexUrl $fedexUrl */
34
- $ this ->config = $ objectManager ->getObject (FedexUrl::class);
49
+ $ this ->contextMock = $ this ->createMock (Context::class);
50
+ $ registry = $ this ->createMock (Registry::class);
51
+ $ config = $ this ->createMock (ScopeConfigInterface::class);
52
+ $ cacheTypeList = $ this ->createMock (TypeListInterface::class);
53
+ $ this ->url = $ this ->createMock (Url::class);
54
+ $ resource = $ this ->createMock (AbstractResource::class);
55
+ $ resourceCollection = $ this ->createMock (AbstractDb::class);
56
+ $ eventManagerMock = $ this ->getMockForAbstractClass (ManagerInterface::class);
57
+ $ eventManagerMock ->expects ($ this ->any ())->method ('dispatch ' );
58
+ $ this ->contextMock ->expects ($ this ->any ())->method ('getEventDispatcher ' )->willReturn ($ eventManagerMock );
59
+
60
+ $ this ->urlConfig = $ objectManager ->getObject (
61
+ FedexUrl::class,
62
+ [
63
+ 'url ' => $ this ->url ,
64
+ 'context ' => $ this ->contextMock ,
65
+ 'registry ' => $ registry ,
66
+ 'config ' => $ config ,
67
+ 'cacheTypeList ' => $ cacheTypeList ,
68
+ 'resource ' => $ resource ,
69
+ 'resourceCollection ' => $ resourceCollection ,
70
+ ]
71
+ );
35
72
}
36
73
37
74
/**
38
75
* @dataProvider validDataProvider
39
76
* @param string|null $data The valid data
40
77
* @throws ValidatorException
41
78
*/
42
- public function testBeforeSave (string $ data = null )
79
+ public function testBeforeSave (string $ data = null ): void
43
80
{
44
- $ this ->config ->setValue ($ data );
45
- $ this ->config ->beforeSave ();
81
+ $ this ->url ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
82
+ $ this ->urlConfig ->setValue ($ data );
83
+ $ this ->urlConfig ->beforeSave ();
84
+ $ this ->assertTrue ($ this ->url ->isValid ($ data ));
46
85
}
47
86
48
87
/**
49
88
* @dataProvider invalidDataProvider
50
89
* @param string $data The invalid data
51
90
*/
52
- public function testBeforeSaveErrors (string $ data )
91
+ public function testBeforeSaveErrors (string $ data ): void
53
92
{
93
+ $ this ->url ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
54
94
$ this ->expectException ('Magento\Framework\Exception\ValidatorException ' );
55
95
$ this ->expectExceptionMessage ('Fedex API endpoint URL \'s must use fedex.com ' );
56
- $ this ->config ->setValue ($ data );
57
- $ this ->config ->beforeSave ();
96
+ $ this ->urlConfig ->setValue ($ data );
97
+ $ this ->urlConfig ->beforeSave ();
58
98
}
59
99
60
100
/**
0 commit comments