Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 3 additions & 4 deletions tests/AbuseTest.php → tests/AbuseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@

use InvalidArgumentException;
use Overblog\DataLoader\DataLoader;
use React\Promise\Promise;
use RuntimeException;

class AbuseTest extends TestCase
abstract class AbuseTestCase extends TestCase
{
/**
* @group provides-descriptive-error-messages-for-api-abuse
Expand All @@ -34,7 +33,7 @@ public function testLoadFunctionRequiresAKeyNotNull()
*/
public function testLoadFunctionRequiresAKeyWith0()
{
self::assertInstanceOf(Promise::class, self::idLoader()->load(0));
self::assertTrue(self::$promiseAdapter->isPromise(self::idLoader()->load(0), true));
}

/**
Expand All @@ -53,7 +52,7 @@ public function testLoadManyFunctionRequiresAListOfKey()
*/
public function testLoadManyFunctionRequiresAListEmptyArrayAccepted()
{
self::assertInstanceOf(Promise::class, self::idLoader()->loadMany([]));
self::assertTrue(self::$promiseAdapter->isPromise(self::idLoader()->loadMany([]), true));
}

/**
Expand Down
51 changes: 4 additions & 47 deletions tests/DataLoadTest.php → tests/DataLoadTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Overblog\DataLoader\DataLoader;
use Overblog\DataLoader\Option;

class DataLoadTest extends TestCase
abstract class DataLoadTestCase extends TestCase
{
/**
* @group primary-api
Expand Down Expand Up @@ -306,7 +306,7 @@ public function testCanRepresentFailuresAndSuccessesSimultaneously()
$promise1->then(null, function ($error) use (&$caughtError) {
$caughtError = $error;
});
DataLoader::await();
DataLoader::await($promise1, false);
$this->assertInstanceOf(\Exception::class, $caughtError);
$this->assertEquals($caughtError->getMessage(), 'Odd: 1');

Expand Down Expand Up @@ -815,50 +815,6 @@ public function testAwaitAlsoAwaitsNewlyCreatedDataloaders()
$this->assertTrue($secondComplete);
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldReturnTheValueOfFulfilledPromiseWithoutNeedingActiveDataLoaderInstance()
{
$expectedValue = 'Ok!';
$value = DataLoader::await(self::$promiseAdapter->createFulfilled($expectedValue));

$this->assertEquals($expectedValue, $value);
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldReturnTheRejectReasonOfRejectedPromiseWithoutNeedingActiveDataLoaderInstance()
{
$expectedException = new \Exception('Rejected!');
$exception = DataLoader::await(self::$promiseAdapter->createRejected($expectedException), false);

$this->assertEquals($expectedException, $exception);
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldThrowTheRejectReasonOfRejectedPromiseWithoutNeedingActiveDataLoaderInstance()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Rejected!');

DataLoader::await(self::$promiseAdapter->createRejected(new Exception('Rejected!')));
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldThrowThrowable()
{
$this->expectException(\Error::class);
$this->expectExceptionMessage('Rejected Error!');

DataLoader::await(self::$promiseAdapter->createRejected(new \Error('Rejected Error!')));
}

public function cacheKey($key)
{
$cacheKey = [];
Expand Down Expand Up @@ -914,6 +870,7 @@ private static function idLoader(?Option $options = null, ?callable $batchLoadFn

private function assertInstanceOfPromise($object)
{
$this->assertTrue(self::$promiseAdapter->isPromise($object, true));
$adapter = self::$promiseAdapter;
$this->assertTrue($adapter->isPromise($object, true));
}
}
23 changes: 23 additions & 0 deletions tests/ReactAbuseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the DataLoaderPhp package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\DataLoader\Test;

use Overblog\PromiseAdapter\Adapter\ReactPromiseAdapter;
use Overblog\PromiseAdapter\PromiseAdapterInterface;

final class ReactAbuseTest extends AbuseTestCase
{
protected function createPromiseAdapter(): PromiseAdapterInterface
{
return new ReactPromiseAdapter();
}
}
68 changes: 68 additions & 0 deletions tests/ReactDataLoadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

/*
* This file is part of the DataLoaderPhp package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\DataLoader\Test;

use Overblog\DataLoader\DataLoader;
use Overblog\PromiseAdapter\Adapter\ReactPromiseAdapter;
use Overblog\PromiseAdapter\PromiseAdapterInterface;

final class ReactDataLoadTest extends DataLoadTestCase
{
protected function createPromiseAdapter(): PromiseAdapterInterface
{
return new ReactPromiseAdapter();
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldReturnTheValueOfFulfilledPromiseWithoutNeedingActiveDataLoaderInstance()
{
$expectedValue = 'Ok!';
$value = DataLoader::await(self::$promiseAdapter->createFulfilled($expectedValue));

$this->assertEquals($expectedValue, $value);
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldReturnTheRejectReasonOfRejectedPromiseWithoutNeedingActiveDataLoaderInstance()
{
$expectedException = new \Exception('Rejected!');
$exception = DataLoader::await(self::$promiseAdapter->createRejected($expectedException), false);

$this->assertEquals($expectedException, $exception);
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldThrowTheRejectReasonOfRejectedPromiseWithoutNeedingActiveDataLoaderInstance()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('Rejected!');

DataLoader::await(self::$promiseAdapter->createRejected(new \Exception('Rejected!')));
}

/**
* @runInSeparateProcess
*/
public function testAwaitShouldThrowThrowable()
{
$this->expectException(\Error::class);
$this->expectExceptionMessage('Rejected Error!');

DataLoader::await(self::$promiseAdapter->createRejected(new \Error('Rejected Error!')));
}
}
14 changes: 12 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Overblog\DataLoader\Test;

use Overblog\PromiseAdapter\Adapter\ReactPromiseAdapter;
use Overblog\DataLoader\DataLoader;
use Overblog\PromiseAdapter\PromiseAdapterInterface;

abstract class TestCase extends \PHPUnit\Framework\TestCase
Expand All @@ -23,6 +23,16 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase

public function setUp(): void
{
self::$promiseAdapter = new ReactPromiseAdapter();
self::$promiseAdapter = $this->createPromiseAdapter();
}

protected function tearDown(): void
{
$instances = new \ReflectionProperty(DataLoader::class, 'instances');
$instances->setValue([]);

parent::tearDown();
}

abstract protected function createPromiseAdapter(): PromiseAdapterInterface;
}
23 changes: 23 additions & 0 deletions tests/WebonyxAbuseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the DataLoaderPhp package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\DataLoader\Test;

use Overblog\PromiseAdapter\Adapter\WebonyxGraphQLSyncPromiseAdapter;
use Overblog\PromiseAdapter\PromiseAdapterInterface;

final class WebonyxAbuseTest extends AbuseTestCase
{
protected function createPromiseAdapter(): PromiseAdapterInterface
{
return new WebonyxGraphQLSyncPromiseAdapter();
}
}
23 changes: 23 additions & 0 deletions tests/WebonyxDataLoadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* This file is part of the DataLoaderPhp package.
*
* (c) Overblog <http://github.com/overblog/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Overblog\DataLoader\Test;

use Overblog\PromiseAdapter\Adapter\WebonyxGraphQLSyncPromiseAdapter;
use Overblog\PromiseAdapter\PromiseAdapterInterface;

final class WebonyxDataLoadTest extends DataLoadTestCase
{
protected function createPromiseAdapter(): PromiseAdapterInterface
{
return new WebonyxGraphQLSyncPromiseAdapter();
}
}
Loading