1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/data-file |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/data-file/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/data-file |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\DataFile\Test\Unit\Format; |
15
|
|
|
|
16
|
|
|
use Graze\DataFile\Test\Format\FakeFormatAware; |
17
|
|
|
use Graze\DataFile\Test\TestCase; |
18
|
|
|
use Mockery as m; |
19
|
|
|
|
20
|
|
|
class FormatAwareTraitTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var FakeFormatAware |
24
|
|
|
*/ |
25
|
|
|
protected $formatAware; |
26
|
|
|
|
27
|
|
|
public function setUp() |
28
|
|
|
{ |
29
|
|
|
$this->formatAware = new FakeFormatAware(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testSetFormat() |
33
|
|
|
{ |
34
|
|
|
$format = m::mock('Graze\DataFile\Format\FormatInterface'); |
35
|
|
|
$this->formatAware->setFormat($format); |
36
|
|
|
|
37
|
|
|
static::assertSame($format, $this->formatAware->getFormat()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testGetFormatType() |
41
|
|
|
{ |
42
|
|
|
$format = m::mock('Graze\DataFile\Format\FormatInterface'); |
43
|
|
|
$this->formatAware->setFormat($format); |
44
|
|
|
|
45
|
|
|
$format->shouldReceive('getType') |
46
|
|
|
->andReturn('test_format'); |
47
|
|
|
|
48
|
|
|
static::assertEquals('test_format', $this->formatAware->getFormatType()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testGetFormatTypeWillReturnNullWithNoFormatIsSpecified() |
52
|
|
|
{ |
53
|
|
|
static::assertNull($this->formatAware->getFormatType()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testCloningWillCloneFormat() |
57
|
|
|
{ |
58
|
|
|
$format = m::mock('Graze\DataFile\Format\FormatInterface'); |
59
|
|
|
$this->formatAware->setFormat($format); |
60
|
|
|
|
61
|
|
|
$newFormatAware = clone $this->formatAware; |
62
|
|
|
|
63
|
|
|
static::assertNotSame($this->formatAware, $newFormatAware); |
64
|
|
|
static::assertNotSame($this->formatAware->getFormat(), $newFormatAware->getFormat()); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|