|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Micrometa\Ports\Item; |
|
4
|
|
|
|
|
5
|
|
|
use Jkphl\Micrometa\Infrastructure\Factory\MicroformatsFactory; |
|
6
|
|
|
use Jkphl\Micrometa\Ports\Exceptions\OutOfBoundsException; |
|
7
|
|
|
use Jkphl\Micrometa\Ports\Item\ItemInterface; |
|
8
|
|
|
use Jkphl\Micrometa\Ports\Item\ItemList; |
|
9
|
|
|
use Jkphl\Micrometa\Tests\MicroformatsFeedTrait; |
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
|
|
12
|
|
|
class ItemListTest extends TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Use the Microformats feed method |
|
16
|
|
|
*/ |
|
17
|
|
|
use MicroformatsFeedTrait; |
|
18
|
|
|
|
|
19
|
|
|
private $feedItemList; |
|
20
|
|
|
|
|
21
|
|
|
protected function setUp(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$this->feedItemList = new ItemList([$this->getFeedItem(), $this->getFeedItem()]); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testNestedItemsCounts() |
|
27
|
|
|
{ |
|
28
|
|
|
// Test the number of nested items |
|
29
|
|
|
self::assertCount(2, $this->feedItemList); |
|
30
|
|
|
self::assertCount(2, $this->feedItemList->getItems()); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testNestedItemsIteration() |
|
34
|
|
|
{ |
|
35
|
|
|
foreach ($this->feedItemList->getItems() as $itemIndex => $entryItem) { |
|
36
|
|
|
self::assertInstanceOf(ItemInterface::class, $entryItem); |
|
37
|
|
|
self::assertIsInt($itemIndex); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testNestedItemsRetrievalViaArrayAccess() |
|
42
|
|
|
{ |
|
43
|
|
|
$entryItems = $this->feedItemList->getFirstItem()->getItems('h-entry'); |
|
44
|
|
|
$entryItem = $entryItems[1]; |
|
45
|
|
|
|
|
46
|
|
|
self::assertInstanceOf(ItemInterface::class, $entryItem); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testFirstNestedItemRetrieval() |
|
50
|
|
|
{ |
|
51
|
|
|
self::assertInstanceOf(ItemInterface::class, $this->feedItemList[0]->getFirstItem('h-entry')); |
|
52
|
|
|
self::assertInstanceOf( |
|
53
|
|
|
ItemInterface::class, |
|
54
|
|
|
$this->feedItemList[0]->getFirstItem('h-entry', MicroformatsFactory::MF2_PROFILE_URI) |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testExistingFirstNestedItem() |
|
59
|
|
|
{ |
|
60
|
|
|
self::assertEquals('John Doe', $this->feedItemList[0]->hEntry()->author->name); |
|
61
|
|
|
self::assertEquals('John Doe', $this->feedItemList->getFirstItem()->hEntry()->author->name); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testNonExistingSecondNestedItem() |
|
65
|
|
|
{ |
|
66
|
|
|
$this->expectException(OutOfBoundsException::class); |
|
67
|
|
|
$this->expectExceptionCode('1492418999'); |
|
68
|
|
|
|
|
69
|
|
|
$this->feedItemList->hEntry(2); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.