Skip to content

Commit

Permalink
Merge pull request #58 from 5am-code/dev
Browse files Browse the repository at this point in the history
Dev to Master: v0.6.2
  • Loading branch information
mechelon authored Dec 28, 2021
2 parents 20a7fcc + 1169e6c commit 4ccef63
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ jobs:
fail-fast: false
matrix:
php:
- '8.1'
- '8.0'
- '7.4'
laravel:
- '8.*'
testbench:
Expand Down
6 changes: 5 additions & 1 deletion src/Endpoints/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ public function children(): BlockCollection
*
* @throws HandlingException
*/
public function append(array|BlockEntity $appendices): BlockEntity
public function append($appendices): BlockEntity
{
if (! is_array($appendices) && ! $appendices instanceof BlockEntity) {
throw new HandlingException('$appendices must be an array or instance of BlockEntity');
}

if (! is_array($appendices)) {
$appendices = [$appendices];
}
Expand Down
7 changes: 7 additions & 0 deletions src/Entities/Blocks/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,11 @@ private static function mapTypeToClass(string $type): string
return Block::class;
}
}

protected static function assertValidTextContent($textContent)
{
if (! is_array($textContent) && ! is_string($textContent)) {
throw new HandlingException('$textContent content must be a string or an array.');
}
}
}
4 changes: 3 additions & 1 deletion src/Entities/Blocks/BulletedListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class BulletedListItem extends TextBlock
{
public static function create(array|string $textContent): BulletedListItem
public static function create($textContent): BulletedListItem
{
self::assertValidTextContent($textContent);

$bulletedListItem = new BulletedListItem();
TextBlock::createTextBlock($bulletedListItem, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/HeadingOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class HeadingOne extends TextBlock
{
public static function create(array|string $textContent): HeadingOne
public static function create($textContent): HeadingOne
{
self::assertValidTextContent($textContent);

$headingOne = new HeadingOne();
TextBlock::createTextBlock($headingOne, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/HeadingThree.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class HeadingThree extends TextBlock
{
public static function create(array|string $textContent): HeadingThree
public static function create($textContent): HeadingThree
{
self::assertValidTextContent($textContent);

$headingThree = new HeadingThree();
HeadingThree::createTextBlock($headingThree, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/HeadingTwo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class HeadingTwo extends TextBlock
{
public static function create(array|string $textContent): HeadingTwo
public static function create($textContent): HeadingTwo
{
self::assertValidTextContent($textContent);

$headingTwo = new HeadingTwo();
HeadingTwo::createTextBlock($headingTwo, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/NumberedListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class NumberedListItem extends TextBlock
{
public static function create(array|string $textContent): NumberedListItem
public static function create($textContent): NumberedListItem
{
self::assertValidTextContent($textContent);

$numberedListItem = new NumberedListItem();
TextBlock::createTextBlock($numberedListItem, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/Paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class Paragraph extends TextBlock
{
public static function create(array|string $textContent): Paragraph
public static function create($textContent): Paragraph
{
self::assertValidTextContent($textContent);

$paragraph = new Paragraph();
TextBlock::createTextBlock($paragraph, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/TextBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
*/
class TextBlock extends Block implements Modifiable
{
protected static function createTextBlock(TextBlock $textBlock, array|string $textContent): TextBlock
protected static function createTextBlock(TextBlock $textBlock, $textContent): TextBlock
{
self::assertValidTextContent($textContent);

if (is_string($textContent)) {
$textContent = [$textContent];
}
Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/ToDo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class ToDo extends TextBlock
{
public static function create(array|string $textContent): ToDo
public static function create($textContent): ToDo
{
self::assertValidTextContent($textContent);

$toDo = new ToDo();
TextBlock::createTextBlock($toDo, $textContent);

Expand Down
4 changes: 3 additions & 1 deletion src/Entities/Blocks/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
*/
class Toggle extends TextBlock
{
public static function create(array|string $textContent): Toggle
public static function create($textContent): Toggle
{
self::assertValidTextContent($textContent);

$toggle = new Toggle();
TextBlock::createTextBlock($toggle, $textContent);

Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Properties/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use FiveamCode\LaravelNotionApi\Entities\Contracts\Modifiable;
use FiveamCode\LaravelNotionApi\Entities\PropertyItems\SelectItem;
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Collection;

/**
* Class Select.
Expand Down
6 changes: 5 additions & 1 deletion src/Query/Filters/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ public static function textFilter(string $property, string $comparisonOperator,
*
* @throws HandlingException
*/
public static function numberFilter(string $property, string $comparisonOperator, float|int $number): Filter
public static function numberFilter(string $property, string $comparisonOperator, $number): Filter
{
if (! is_numeric($number)) {
throw new HandlingException('The number must be numeric.');
}

self::isValidComparisonOperatorFor('number', $comparisonOperator);

return new Filter($property, 'number', [$comparisonOperator => $number]);
Expand Down
30 changes: 30 additions & 0 deletions tests/EndpointBlocksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use FiveamCode\LaravelNotionApi\Entities\Blocks\Video;
use FiveamCode\LaravelNotionApi\Entities\Collections\BlockCollection;
use FiveamCode\LaravelNotionApi\Exceptions\NotionException;
use FiveamCode\LaravelNotionApi\Exceptions\HandlingException;
use Illuminate\Support\Facades\Http;
use Notion;

Expand Down Expand Up @@ -292,6 +293,35 @@ public function it_returns_parent_block_in_which_new_blocks_have_been_successful
$this->assertInstanceOf(Block::class, $parentBlock);
}

/**
* @dataProvider classProvider
*/
public function classProvider(): array
{
return [
[BulletedListItem::class],
[HeadingOne::class],
[HeadingTwo::class],
[HeadingThree::class],
[NumberedListItem::class],
[Paragraph::class],
[ToDo::class],
[Toggle::class],
];
}

/**
* @test
* @dataProvider classProvider
*
* @param $entityClass
*/
public function it_throws_an_handling_exception_for_wrong_type($entityClass)
{
$this->expectException(HandlingException::class);
$paragraph = $entityClass::create(new \stdClass());
}

/** @test */
public function it_retrieves_a_single_block()
{
Expand Down
6 changes: 5 additions & 1 deletion tests/NotionApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ protected function getPackageAliases($app): array
];
}

protected function assertContainsInstanceOf(string $class, Collection|array $haystack): bool
protected function assertContainsInstanceOf(string $class, $haystack): bool
{
if (! is_array($haystack) && ! ($haystack instanceof Collection)) {
throw new \InvalidArgumentException('$haystack must be an array or a Collection');
}

foreach ($haystack as $item) {
if (get_class($item) === $class) {
return true;
Expand Down

0 comments on commit 4ccef63

Please sign in to comment.