AdapterChainEventTest.php 2.56 KB
Newer Older
Bertrand Gauthier's avatar
Bertrand Gauthier committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php

namespace ZfcUserTest\Authentication\Adapter;

use ZfcUser\Authentication\Adapter\AdapterChainEvent;

class AdapterChainEventTest extends \PHPUnit_Framework_TestCase
{
    /**
     * The object to be tested.
     *
     * @var AdapterChainEvent
     */
    protected $event;

    /**
     * Prepare the object to be tested.
     */
    protected function setUp()
    {
        $this->event = new AdapterChainEvent();
    }

    /**
     * @covers \ZfcUser\Authentication\Adapter\AdapterChainEvent::getCode
     * @covers \ZfcUser\Authentication\Adapter\AdapterChainEvent::setCode
     * @covers \ZfcUser\Authentication\Adapter\AdapterChainEvent::getMessages
     * @covers \ZfcUser\Authentication\Adapter\AdapterChainEvent::setMessages
     */
    public function testCodeAndMessages()
    {
        $testCode = 103;
        $testMessages = array('Message recieved loud and clear.');

        $this->event->setCode($testCode);
        $this->assertEquals($testCode, $this->event->getCode(), "Asserting code values match.");

        $this->event->setMessages($testMessages);
        $this->assertEquals($testMessages, $this->event->getMessages(), "Asserting messages values match.");
    }

    /**
     * @depends testCodeAndMessages
     * @covers \ZfcUser\Authentication\Adapter\AdapterChainEvent::getIdentity
     * @covers \ZfcUser\Authentication\Adapter\AdapterChainEvent::setIdentity
     */
    public function testIdentity()
    {
        $testCode = 123;
        $testMessages = array('The message.');
        $testIdentity = 'the_user';

        $this->event->setCode($testCode);
        $this->event->setMessages($testMessages);

        $this->event->setIdentity($testIdentity);

        $this->assertEquals($testCode, $this->event->getCode(), "Asserting the code persisted.");
        $this->assertEquals($testMessages, $this->event->getMessages(), "Asserting the messages persisted.");
        $this->assertEquals($testIdentity, $this->event->getIdentity(), "Asserting the identity matches");

        $this->event->setIdentity();

        $this->assertNull($this->event->getCode(), "Asserting the code has been cleared.");
        $this->assertEquals(array(), $this->event->getMessages(), "Asserting the messages have been cleared.");
        $this->assertNull($this->event->getIdentity(), "Asserting the identity has been cleared");
    }

    public function testRequest()
    {
Bertrand Gauthier's avatar
Bertrand Gauthier committed
71
        $request = $this->getMock('Laminas\Stdlib\RequestInterface');
Bertrand Gauthier's avatar
Bertrand Gauthier committed
72
73
        $this->event->setRequest($request);

Bertrand Gauthier's avatar
Bertrand Gauthier committed
74
        $this->assertInstanceOf('Laminas\Stdlib\RequestInterface', $this->event->getRequest());
Bertrand Gauthier's avatar
Bertrand Gauthier committed
75
76
    }
}