Skip to content

Commit 4ccef63

Browse files
authored
Merge pull request #58 from 5am-code/dev
Dev to Master: v0.6.2
2 parents 20a7fcc + 1169e6c commit 4ccef63

16 files changed

+82
-13
lines changed

.github/workflows/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
php:
13+
- '8.1'
1314
- '8.0'
15+
- '7.4'
1416
laravel:
1517
- '8.*'
1618
testbench:

src/Endpoints/Block.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ public function children(): BlockCollection
8181
*
8282
* @throws HandlingException
8383
*/
84-
public function append(array|BlockEntity $appendices): BlockEntity
84+
public function append($appendices): BlockEntity
8585
{
86+
if (! is_array($appendices) && ! $appendices instanceof BlockEntity) {
87+
throw new HandlingException('$appendices must be an array or instance of BlockEntity');
88+
}
89+
8690
if (! is_array($appendices)) {
8791
$appendices = [$appendices];
8892
}

src/Entities/Blocks/Block.php

+7
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,11 @@ private static function mapTypeToClass(string $type): string
212212
return Block::class;
213213
}
214214
}
215+
216+
protected static function assertValidTextContent($textContent)
217+
{
218+
if (! is_array($textContent) && ! is_string($textContent)) {
219+
throw new HandlingException('$textContent content must be a string or an array.');
220+
}
221+
}
215222
}

src/Entities/Blocks/BulletedListItem.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class BulletedListItem extends TextBlock
99
{
10-
public static function create(array|string $textContent): BulletedListItem
10+
public static function create($textContent): BulletedListItem
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$bulletedListItem = new BulletedListItem();
1315
TextBlock::createTextBlock($bulletedListItem, $textContent);
1416

src/Entities/Blocks/HeadingOne.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class HeadingOne extends TextBlock
99
{
10-
public static function create(array|string $textContent): HeadingOne
10+
public static function create($textContent): HeadingOne
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$headingOne = new HeadingOne();
1315
TextBlock::createTextBlock($headingOne, $textContent);
1416

src/Entities/Blocks/HeadingThree.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class HeadingThree extends TextBlock
99
{
10-
public static function create(array|string $textContent): HeadingThree
10+
public static function create($textContent): HeadingThree
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$headingThree = new HeadingThree();
1315
HeadingThree::createTextBlock($headingThree, $textContent);
1416

src/Entities/Blocks/HeadingTwo.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class HeadingTwo extends TextBlock
99
{
10-
public static function create(array|string $textContent): HeadingTwo
10+
public static function create($textContent): HeadingTwo
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$headingTwo = new HeadingTwo();
1315
HeadingTwo::createTextBlock($headingTwo, $textContent);
1416

src/Entities/Blocks/NumberedListItem.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class NumberedListItem extends TextBlock
99
{
10-
public static function create(array|string $textContent): NumberedListItem
10+
public static function create($textContent): NumberedListItem
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$numberedListItem = new NumberedListItem();
1315
TextBlock::createTextBlock($numberedListItem, $textContent);
1416

src/Entities/Blocks/Paragraph.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class Paragraph extends TextBlock
99
{
10-
public static function create(array|string $textContent): Paragraph
10+
public static function create($textContent): Paragraph
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$paragraph = new Paragraph();
1315
TextBlock::createTextBlock($paragraph, $textContent);
1416

src/Entities/Blocks/TextBlock.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
*/
1111
class TextBlock extends Block implements Modifiable
1212
{
13-
protected static function createTextBlock(TextBlock $textBlock, array|string $textContent): TextBlock
13+
protected static function createTextBlock(TextBlock $textBlock, $textContent): TextBlock
1414
{
15+
self::assertValidTextContent($textContent);
16+
1517
if (is_string($textContent)) {
1618
$textContent = [$textContent];
1719
}

src/Entities/Blocks/ToDo.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class ToDo extends TextBlock
99
{
10-
public static function create(array|string $textContent): ToDo
10+
public static function create($textContent): ToDo
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$toDo = new ToDo();
1315
TextBlock::createTextBlock($toDo, $textContent);
1416

src/Entities/Blocks/Toggle.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
*/
88
class Toggle extends TextBlock
99
{
10-
public static function create(array|string $textContent): Toggle
10+
public static function create($textContent): Toggle
1111
{
12+
self::assertValidTextContent($textContent);
13+
1214
$toggle = new Toggle();
1315
TextBlock::createTextBlock($toggle, $textContent);
1416

src/Entities/Properties/Select.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable;
66
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\SelectItem;
77
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
8-
use Illuminate\Database\Eloquent\Collection;
8+
use Illuminate\Support\Collection;
99

1010
/**
1111
* Class Select.

src/Query/Filters/Filter.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ public static function textFilter(string $property, string $comparisonOperator,
7575
*
7676
* @throws HandlingException
7777
*/
78-
public static function numberFilter(string $property, string $comparisonOperator, float|int $number): Filter
78+
public static function numberFilter(string $property, string $comparisonOperator, $number): Filter
7979
{
80+
if (! is_numeric($number)) {
81+
throw new HandlingException('The number must be numeric.');
82+
}
83+
8084
self::isValidComparisonOperatorFor('number', $comparisonOperator);
8185

8286
return new Filter($property, 'number', [$comparisonOperator => $number]);

tests/EndpointBlocksTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use FiveamCode\LaravelNotionApi\Entities\Blocks\Video;
1919
use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
2020
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
21+
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
2122
use Illuminate\Support\Facades\Http;
2223
use Notion;
2324

@@ -292,6 +293,35 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful
292293
$this->assertInstanceOf(Block::class, $parentBlock);
293294
}
294295

296+
/**
297+
* @dataProvider classProvider
298+
*/
299+
public function classProvider(): array
300+
{
301+
return [
302+
[BulletedListItem::class],
303+
[HeadingOne::class],
304+
[HeadingTwo::class],
305+
[HeadingThree::class],
306+
[NumberedListItem::class],
307+
[Paragraph::class],
308+
[ToDo::class],
309+
[Toggle::class],
310+
];
311+
}
312+
313+
/**
314+
* @test
315+
* @dataProvider classProvider
316+
*
317+
* @param $entityClass
318+
*/
319+
public function it_throws_an_handling_exception_for_wrong_type($entityClass)
320+
{
321+
$this->expectException(HandlingException::class);
322+
$paragraph = $entityClass::create(new \stdClass());
323+
}
324+
295325
/** @test */
296326
public function it_retrieves_a_single_block()
297327
{

tests/NotionApiTest.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@ protected function getPackageAliases($app): array
3636
];
3737
}
3838

39-
protected function assertContainsInstanceOf(string $class, Collection|array $haystack): bool
39+
protected function assertContainsInstanceOf(string $class, $haystack): bool
4040
{
41+
if (! is_array($haystack) && ! ($haystack instanceof Collection)) {
42+
throw new \InvalidArgumentException('$haystack must be an array or a Collection');
43+
}
44+
4145
foreach ($haystack as $item) {
4246
if (get_class($item) === $class) {
4347
return true;

0 commit comments

Comments
 (0)