Skip to content

Commit 613c0b7

Browse files
committed
Fixed tests
1 parent 9b60155 commit 613c0b7

File tree

7 files changed

+35
-6
lines changed

7 files changed

+35
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ Homestead.yaml
2121
Homestead.json
2222
/.vagrant
2323
.phpunit.result.cache
24+
.phpunit.cache/test-results

src/Concerns/HasLayoutInstances.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function instancesValues() : array
132132
* @param null|string $key
133133
* @return int
134134
*/
135-
public function count(?string $key = null)
135+
public function count(?string $key = null): int
136136
{
137137
if(! $this->instances) {
138138
return 0;

src/Concerns/HasLayouts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ trait HasLayouts
2525
* @param null|int $limit
2626
* @return $this
2727
*/
28-
public function register($layout, int $limit = null) : Flexible
28+
public function register(string|Layout|callable $layout, ?int $limit = null) : Flexible
2929
{
3030
if(is_string($layout) && is_a($layout, Layout::class, true)) {
3131
$layout = new $layout;

src/Contracts/Flexible.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface Flexible
1414
* @param null|int $limit
1515
* @return $this
1616
*/
17-
public function register($layout, int $limit = null) : Flexible;
17+
public function register(string|Layout|callable $layout, ?int $limit = null) : Flexible;
1818

1919
/**
2020
* Check if the Flexible container has a defined layout for given key.
@@ -94,5 +94,5 @@ public function instancesValues() : array;
9494
* @param null|string $key
9595
* @return int
9696
*/
97-
public function count(?string $key = null);
97+
public function count(?string $key = null): int;
9898
}

src/Exceptions/InvalidLayoutKeyException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class InvalidLayoutKeyException extends InvalidArgumentException
1515
* @param bool $exists
1616
* @return \InvalidArgumentException
1717
*/
18-
static public function make(Layout $layout, string $key = null, $exists = false) : InvalidArgumentException
18+
static public function make(Layout $layout, ?string $key = null, bool $exists = false) : InvalidArgumentException
1919
{
2020
$classname = get_class($layout);
2121

src/Layout.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ class Layout implements LayoutInterface, ArrayAccess, JsonSerializable, Arrayabl
1717
use HasAttributes;
1818
use HidesAttributes;
1919

20+
/**
21+
* Indicates if the model exists.
22+
*
23+
* @var bool
24+
*/
25+
public $exists = false;
26+
2027
/**
2128
* A short unique name for this Layout, usually used by front-end components
2229
*
@@ -331,6 +338,26 @@ public function toButtonArray() : array
331338
];
332339
}
333340

341+
/**
342+
* This method is called by the HasAttributes trait, and is usually
343+
* defined on a model class. In this case, we don't need to handle
344+
* it, but we do need to have the method to avoid errors.
345+
*/
346+
public function relationResolver($classname, $key)
347+
{
348+
return false;
349+
}
350+
351+
/**
352+
* This method is called by the HasAttributes trait, and is usually
353+
* defined on a model class. In this case, we don't need to handle
354+
* it, but we do need to have the method to avoid errors.
355+
*/
356+
public function preventsAccessingMissingAttributes()
357+
{
358+
return false;
359+
}
360+
334361
/**
335362
* Transform layout for front-end serialization (AJAX requests usage).
336363
*

tests/Unit/LayoutRegistrationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Whitecube\LaravelFlexibleContent\Exceptions\InvalidLayoutException;
88
use Whitecube\LaravelFlexibleContent\Exceptions\InvalidLayoutKeyException;
99
use Tests\Fixtures\CustomLayout;
10+
use TypeError;
1011

1112
it('can register and configure a basic layout using a closure as argument', function() {
1213
$flexible = new Flexible();
@@ -57,7 +58,7 @@
5758
$flexible = new Flexible();
5859

5960
$flexible->register(new Flexible());
60-
})->throws(InvalidLayoutException::class);
61+
})->throws(TypeError::class);
6162

6263
it('cannot register a layout without defined key', function() {
6364
$flexible = new Flexible();

0 commit comments

Comments
 (0)