Completed
Push — master ( e2e6d9...5aa43e )
by Joschi
02:56
created

AuthorTest::testLoadArticleObjectInvalidAuthor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Kernel
8
 * @subpackage  Apparat\Kernel\Tests
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Tests;
38
39
use Apparat\Object\Domain\Factory\AuthorFactory;
40
use Apparat\Object\Domain\Model\Author\ApparatAuthor;
41
use Apparat\Object\Domain\Model\Author\GenericAuthor;
42
use Apparat\Object\Domain\Model\Path\RepositoryPath;
43
use Apparat\Object\Domain\Repository\Repository;
44
use Apparat\Object\Infrastructure\Repository\FileAdapterStrategy;
45
46
/**
47
 * Author tests
48
 *
49
 * @package Apparat\Kernel
50
 * @subpackage Apparat\Object\Tests
51
 */
52
class AuthorTest extends AbstractTest
53
{
54
    /**
55
     * Test repository
56
     *
57
     * @var Repository
58
     */
59
    protected static $repository = null;
60
61
    /**
62
     * Generic author string
63
     *
64
     * @var string
65
     */
66
    const GENERIC_AUTHOR = 'John Doe <[email protected]> (http://doe.com)';
67
68
    /**
69
     * Setup
70
     */
71
    public static function setUpBeforeClass()
72
    {
73
        \Apparat\Object\Ports\Repository::register(
74
            getenv('REPOSITORY_URL'), [
75
                'type' => FileAdapterStrategy::TYPE,
76
                'root' => __DIR__ . DIRECTORY_SEPARATOR . 'Fixture',
77
            ]
78
        );
79
80
        self::$repository = \Apparat\Object\Ports\Repository::instance(getenv('REPOSITORY_URL'));
81
    }
82
83
    /**
84
     * Load an article and test an invalid author
85
     *
86
     * @expectedException \Apparat\Object\Domain\Model\Properties\InvalidArgumentException
87
     * @expectedExceptionCode 1451425516
88
     */
89
    public function testLoadArticleObjectInvalidAuthor()
90
    {
91
        $articleObjectPath = new RepositoryPath(self::$repository, '/2016/02/16/4.article/4');
92
        self::$repository->loadObject($articleObjectPath);
93
    }
94
95
    /**
96
     * Test an invalid author format
97
     *
98
     * @expectedException \Apparat\Object\Domain\Model\Author\InvalidArgumentException
99
     * @expectedExceptionCode 1451426440
100
     */
101
    public function testInvalidAuthorFormat()
102
    {
103
        AuthorFactory::createFromString('');
104
    }
105
106
    /**
107
     * Test apparat author unserialization
108
     */
109
    public function testApparatAuthorUnserialization() {
110
        $this->assertInstanceOf(ApparatAuthor::class, ApparatAuthor::unserialize('/repo/2016/01/08/2.contact/2'));
111
    }
112
113
    /**
114
     * Test the serialization of a generic author
115
     */
116
    public function testGenericAuthorSerialization() {
117
        $genericAuthor = GenericAuthor::unserialize(self::GENERIC_AUTHOR);
118
        $this->assertEquals(self::GENERIC_AUTHOR, $genericAuthor->serialize());
119
    }
120
}
121