Completed
Branch master (5105da)
by Stefano
02:21
created

ServiceTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 30
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
class ServiceTest extends PHPUnit_Framework_TestCase {
5
6
    public function testSimpleServiceContainer(){
7
      Service::register('email',function() {
8
          return "EMAIL SERVICE";
9
      });
10
      $this->assertEquals(Service::email() . Service::email(), "EMAIL SERVICEEMAIL SERVICE");
11
    }
12
13
    public function testSimpleServicePersistence(){
14
      Service::register('test',function($data) {
15
          return (object)["data" => $data];
16
      });
17
      $this->assertEquals(Service::test('--TEST--')->data, "--TEST--");
18
      $this->assertEquals(Service::test()->data, "--TEST--");
19
      $this->assertEquals(Service::test("NOT ME!")->data, "--TEST--");
20
    }
21
22
    public function testSimpleServiceFactory(){
23
      Service::registerFactory('foos',function($bar) {
24
          return (object)["data" => $bar];
25
      });
26
      $this->assertEquals(implode('',[
27
        Service::foos('A')->data,
28
        Service::foos('B')->data,
29
        Service::foos('C')->data,
30
      ]), "ABC");
31
    }
32
33
}
34