Completed
Push — develop ( c09155...432462 )
by
unknown
16:18
created

OrganizationEntityMock::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6667
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace JobsTest\Factory\Form;
12
13
use Jobs\Factory\Form\ActiveOrganizationSelectFactory;
14
use Organizations\Entity\Organization;
15
use Organizations\Entity\OrganizationContact;
16
use Organizations\Entity\OrganizationName;
17
18
/**
19
 * Tests for \Jobs\Factory\Form\ActiveOrganizationSelect
20
 * 
21
 * @covers \Jobs\Factory\Form\ActiveOrganizationSelectFactory
22
 * @author Mathias Gelhausen <[email protected]>
23
 *  
24
 */
25
class ActiveOrganizationSelectFactoryTest extends \PHPUnit_Framework_TestCase
26
{
27
28
    public function testImplementsFactoryInterface()
29
    {
30
        $target = new ActiveOrganizationSelectFactory();
31
32
        $this->assertInstanceOf('\Zend\ServiceManager\FactoryInterface', $target);
33
    }
34
35
    public function testCreatesOrganizationSelect()
36
    {
37
        $org1Values = [
38
            'id' => 'org1',
39
            'name' => 'Org1',
40
            'city' => 'Org1City',
41
            'street' => 'Org1Street',
42
            'number' => '1'
43
        ];
44
45
        $org1 = new OrganizationEntityMock($org1Values);
46
        $orgs = [ $org1 ];
47
48
49
        $jobRepo = $this->getMockBuilder('\Jobs\Repository\Job')->disableOriginalConstructor()->getMock();
50
51
        $jobRepo->expects($this->once())->method('findActiveOrganizations')->willReturn($orgs);
52
53
        $repos = $this->getMockBuilder('\Core\Repository\RepositoryService')->disableOriginalConstructor()->getMock();
54
55
        $repos->expects($this->once())->method('get')->with('Jobs')->willReturn($jobRepo);
56
57
        $services = $this->getMockBuilder('\Zend\ServiceManager\ServiceManager')->disableOriginalConstructor()->getMock();
58
59
        $services->expects($this->once())->method('get')->with('repositories')->willReturn($repos);
60
61
        $formsMock = $this->getMockBuilder('\Zend\Form\FormElementManager')->disableOriginalConstructor()->getMock();
62
63
        $formsMock->expects($this->once())->method('getServiceLocator')->willReturn($services);
64
65
        $target = new ActiveOrganizationSelectFactory();
66
67
        $select = $target->createService($formsMock);
68
69
        $this->assertInstanceOf('\Jobs\Form\OrganizationSelect', $select);
70
71
        $actual = $select->getValueOptions();
72
        $expected = [ '0' => '', 'org1' => 'Org1|Org1City|Org1Street|1|' ];
73
74
        $this->assertEquals($expected, $actual);
75
    }
76
}
77
78
class OrganizationEntityMock extends Organization
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
79
{
80
    public function __construct(array $values)
81
    {
82
        $this->id = $values['id'];
83
        $this->organizationName = new OrganizationName($values['name']);
84
        $contact = new OrganizationContact();
85
        $contact->setCity($values['city'])->setStreet($values['street'])->setHouseNumber($values['number']);
86
        $this->contact = $contact;
87
88
    }
89
}