1 | <?php |
||
13 | class ContentContext implements Context, SnippetAcceptingContext |
||
14 | { |
||
15 | /** @var \eZ\Publish\API\Repository\Values\Content\Content */ |
||
16 | private $currentContent; |
||
17 | |||
18 | /** @var \eZ\Publish\API\Repository\Values\Content\Content */ |
||
19 | private $currentDraft; |
||
20 | |||
21 | /** @var \eZ\Publish\API\Repository\Repository */ |
||
22 | private $repository; |
||
23 | |||
24 | public function __construct(Repository $repository) |
||
28 | |||
29 | /** |
||
30 | * @Given /^I create an folder draft$/ |
||
31 | */ |
||
32 | public function iCreateAnFolderDraft() |
||
33 | { |
||
34 | $this->currentDraft = $this->createDraft( |
||
35 | 'folder', |
||
36 | [ |
||
37 | 'name' => 'Preview draft ' . date('c'), |
||
38 | 'short_description' => '<?xml version="1.0" encoding="UTF-8"?><section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ezxhtml="http://ez.no/xmlns/ezpublish/docbook/xhtml" xmlns:ezcustom="http://ez.no/xmlns/ezpublish/docbook/custom" version="5.0-variant ezpublish-1.0"><para>This is a paragraph.</para></section>', |
||
39 | ] |
||
40 | ); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @Given /^I create a draft of an existing content item$/ |
||
45 | */ |
||
46 | public function iCreateADraftOfAnExistingContentItem() |
||
55 | |||
56 | /** |
||
57 | * Uses a content type identifier + a hash of fields values |
||
58 | * to create and publish a content item below the root location. |
||
59 | * |
||
60 | * @param string $contentTypeIdentifier |
||
61 | * @param array $fields Hash of field def identifier => field value |
||
62 | * |
||
63 | * @return Content the created content item. |
||
64 | */ |
||
65 | public function createContentItem($contentTypeIdentifier, array $fields) |
||
79 | |||
80 | public function createDraftForContent(Content $content) |
||
90 | |||
91 | public function getCurrentDraft() |
||
99 | |||
100 | public function updateDraft($fields) |
||
118 | |||
119 | /** |
||
120 | * Uses a content type identifier + a hash of fields values |
||
121 | * to create and publish a draft below the root location. |
||
122 | * |
||
123 | * @param string $contentTypeIdentifier |
||
124 | * @param array $fields Hash of field def identifier => field value |
||
125 | * |
||
126 | * @return Content the created draft. |
||
127 | */ |
||
128 | public function createDraft($contentTypeIdentifier, array $fields) |
||
154 | } |
||
155 |
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: