1 | <?php |
||
16 | class ServiceRepositoryTest extends TestCase |
||
17 | { |
||
18 | public function testGetServiceByUrl() |
||
19 | { |
||
20 | $serviceHost = Mockery::mock(ServiceHost::class); |
||
21 | $serviceHost->shouldReceive('where->first')->andReturn(null); |
||
22 | app()->instance(ServiceHost::class, $serviceHost); |
||
23 | $this->assertNull(app()->make(ServiceRepository::class)->getServiceByUrl('http://www.baidu.com')); |
||
24 | |||
25 | $service = Mockery::mock(Service::class); |
||
26 | $serviceHost = Mockery::mock(ServiceHost::class); |
||
27 | $serviceHost->shouldReceive('where->first')->andReturn((object) ['service' => $service]); |
||
28 | app()->instance(ServiceHost::class, $serviceHost); |
||
29 | $this->assertEquals($service, app()->make(ServiceRepository::class)->getServiceByUrl('http://www.baidu.com')); |
||
30 | } |
||
31 | |||
32 | public function testIsUrlValid() |
||
33 | { |
||
34 | $serviceRepository = Mockery::mock(ServiceRepository::class) |
||
35 | ->makePartial() |
||
36 | ->shouldReceive('getServiceByUrl') |
||
37 | ->andReturn(null) |
||
38 | ->getMock(); |
||
39 | $this->assertFalse($serviceRepository->isUrlValid('http://www.baidu.com')); |
||
40 | |||
41 | $serviceRepository = Mockery::mock(ServiceRepository::class) |
||
42 | ->makePartial() |
||
43 | ->shouldReceive('getServiceByUrl') |
||
44 | ->andReturn((object) ['enabled' => true]) |
||
45 | ->getMock(); |
||
46 | $this->assertTrue($serviceRepository->isUrlValid('http://www.baidu.com')); |
||
47 | } |
||
48 | } |
||
49 |