88
99namespace Magento \Fedex \Test \Unit \Model \Config \Backend ;
1010
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 ;
1116use Magento \Framework \Exception \ValidatorException ;
17+ use Magento \Framework \Model \Context ;
18+ use Magento \Framework \Registry ;
1219use 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 ;
1423use PHPUnit \Framework \TestCase ;
1524
1625/**
@@ -22,39 +31,70 @@ class FedexUrlTest extends TestCase
2231 /**
2332 * @var FedexUrl
2433 */
25- private $ config ;
34+ private $ urlConfig ;
2635
2736 /**
28- * @return void
37+ * @var Url
2938 */
39+ private $ url ;
40+
41+ /**
42+ * @var Context|MockObject
43+ */
44+ private $ contextMock ;
45+
3046 protected function setUp (): void
3147 {
3248 $ 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+ );
3572 }
3673
3774 /**
3875 * @dataProvider validDataProvider
3976 * @param string|null $data The valid data
4077 * @throws ValidatorException
4178 */
42- public function testBeforeSave (string $ data = null )
79+ public function testBeforeSave (string $ data = null ): void
4380 {
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 ));
4685 }
4786
4887 /**
4988 * @dataProvider invalidDataProvider
5089 * @param string $data The invalid data
5190 */
52- public function testBeforeSaveErrors (string $ data )
91+ public function testBeforeSaveErrors (string $ data ): void
5392 {
93+ $ this ->url ->expects ($ this ->any ())->method ('isValid ' )->willReturn (true );
5494 $ this ->expectException ('Magento\Framework\Exception\ValidatorException ' );
5595 $ 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 ();
5898 }
5999
60100 /**
0 commit comments