Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev to Master: v0.6.2 #58

Merged
merged 15 commits into from
Dec 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -10,7 +10,9 @@ jobs:
fail-fast: false
matrix:
php:
- '8.1'
- '8.0'
- '7.4'
laravel:
- '8.*'
testbench:
6 changes: 5 additions & 1 deletion src/Endpoints/Block.php
Original file line number Diff line number Diff line change
@@ -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];
}
7 changes: 7 additions & 0 deletions src/Entities/Blocks/Block.php
Original file line number Diff line number Diff line change
@@ -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
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/HeadingOne.php
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/HeadingThree.php
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/HeadingTwo.php
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/NumberedListItem.php
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/Paragraph.php
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/TextBlock.php
Original file line number Diff line number Diff line change
@@ -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];
}
4 changes: 3 additions & 1 deletion src/Entities/Blocks/ToDo.php
Original file line number Diff line number Diff line change
@@ -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);

4 changes: 3 additions & 1 deletion src/Entities/Blocks/Toggle.php
Original file line number Diff line number Diff line change
@@ -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);

2 changes: 1 addition & 1 deletion src/Entities/Properties/Select.php
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 5 additions & 1 deletion src/Query/Filters/Filter.php
Original file line number Diff line number Diff line change
@@ -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]);
30 changes: 30 additions & 0 deletions tests/EndpointBlocksTest.php
Original file line number Diff line number Diff line change
@@ -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;

@@ -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()
{
6 changes: 5 additions & 1 deletion tests/NotionApiTest.php
Original file line number Diff line number Diff line change
@@ -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;