Completed
Branch proxy (abe564)
by leo
03:38
created

ServiceRepositoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 6
1
<?php
2
3
namespace Leo108\CAS\Repositories;
4
5
use Mockery;
6
use TestCase;
7
use Leo108\CAS\Models\Service;
8
use Leo108\CAS\Models\ServiceHost;
9
10
/**
11
 * Created by PhpStorm.
12
 * User: leo108
13
 * Date: 2016/9/29
14
 * Time: 10:15
15
 */
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