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\Node; |
15
|
|
|
|
16
|
|
|
use Graze\DataFile\Format\CsvFormat; |
17
|
|
|
use Graze\DataFile\Format\CsvFormatInterface; |
18
|
|
|
use Graze\DataFile\Format\FormatAwareInterface; |
19
|
|
|
use Graze\DataFile\Format\FormatInterface; |
20
|
|
|
use Graze\DataFile\Node\LocalFile; |
21
|
|
|
use Graze\DataFile\Test\TestCase; |
22
|
|
|
|
23
|
|
|
class LocalCsvFileTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
public function testCloneWillCloneTheCsvDefinition() |
26
|
|
|
{ |
27
|
|
|
$file = (new LocalFile('some/path/here')) |
28
|
|
|
->setFormat(new CsvFormat()); |
29
|
|
|
$clone = $file->getClone(); |
30
|
|
|
|
31
|
|
|
static::assertNotSame($file, $clone); |
32
|
|
|
|
33
|
|
|
$clone->getFormat()->setDelimiter('--'); |
|
|
|
|
34
|
|
|
|
35
|
|
|
static::assertNotEquals($file->getFormat()->getDelimiter(), $clone->getFormat()->getDelimiter()); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testImplementsInterface() |
39
|
|
|
{ |
40
|
|
|
$file = (new LocalFile('fake/path')) |
41
|
|
|
->setFormat(new CsvFormat()); |
42
|
|
|
|
43
|
|
|
static::assertInstanceOf(FormatAwareInterface::class, $file); |
44
|
|
|
static::assertInstanceOf(FormatInterface::class, $file->getFormat()); |
45
|
|
|
static::assertInstanceOf(CsvFormatInterface::class, $file->getFormat()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testFormatTypeIsCsv() |
49
|
|
|
{ |
50
|
|
|
$file = (new LocalFile('fake/path')) |
51
|
|
|
->setFormat(new CsvFormat()); |
52
|
|
|
|
53
|
|
|
static::assertEquals('csv', $file->getFormatType()); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: