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

Support for PHP 81 #542

Merged
merged 2 commits into from
Mar 7, 2022
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
3 changes: 2 additions & 1 deletion src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public function parseIncludes($includes)

foreach ($includes as $include) {
list($includeName, $allModifiersStr) = array_pad(explode(':', $include, 2), 2, '');
list($allModifiersStr, $subRelations) = array_pad(explode('.', $allModifiersStr, 2), 2, null);
$a = $allModifiersStr ? explode('.', $allModifiersStr, 2) : [''];
list($allModifiersStr, $subRelations) = array_pad($a, 2, null);

// Trim it down to a cool level of recursion
$includeName = $this->trimToAcceptableRecursionLevel($includeName);
Expand Down
12 changes: 4 additions & 8 deletions src/ParamBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public function __unset($key)
*
* @return bool
*/
#[\ReturnTypeWillChange]
public function offsetExists($key)
public function offsetExists($key): bool
{
return $this->__isset($key);
}
Expand Down Expand Up @@ -134,8 +133,7 @@ public function offsetGet($key)
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetSet($key, $value)
public function offsetSet($key, $value): void
{
throw new \LogicException('Modifying parameters is not permitted');
}
Expand All @@ -149,8 +147,7 @@ public function offsetSet($key, $value)
*
* @return void
*/
#[\ReturnTypeWillChange]
public function offsetUnset($key)
public function offsetUnset($key): void
{
throw new \LogicException('Modifying parameters is not permitted');
}
Expand All @@ -160,8 +157,7 @@ public function offsetUnset($key)
*
* @return \ArrayIterator
*/
#[\ReturnTypeWillChange]
public function getIterator()
public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->params);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Scope.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,7 @@ public function toArray()
/**
* @return mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->toArray();
}
Expand Down
25 changes: 9 additions & 16 deletions test/ManagerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace League\Fractal\Test;

use InvalidArgumentException;
use League\Fractal\Manager;
use League\Fractal\ParamBag;
use League\Fractal\Resource\Collection;
Expand All @@ -17,23 +18,19 @@ public function testParseIncludeSelfie()
$this->assertInstanceOf(get_class($manager), $manager->parseIncludes(['foo']));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The parseIncludes() method expects a string or an array. NULL given
*/
public function testInvalidParseInclude()
{
$this->expectExceptionObject(new InvalidArgumentException('The parseIncludes() method expects a string or an array. NULL given'));

$manager = new Manager();

$manager->parseIncludes(null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The parseIncludes() method expects a string or an array. integer given
*/
public function testIceTParseInclude()
{
$this->expectExceptionObject(new InvalidArgumentException('The parseIncludes() method expects a string or an array. integer given'));

$manager = new Manager();

$manager->parseIncludes(99);
Expand Down Expand Up @@ -99,23 +96,19 @@ public function testParseExcludeSelfie()
$this->assertInstanceOf(get_class($manager), $manager->parseExcludes(['foo']));
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The parseExcludes() method expects a string or an array. NULL given
*/
public function testInvalidParseExclude()
{
$this->expectExceptionObject(new InvalidArgumentException('The parseExcludes() method expects a string or an array. NULL given'));

$manager = new Manager();

$manager->parseExcludes(null);
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage The parseExcludes() method expects a string or an array. integer given
*/
public function testIceTParseExclude()
{
$this->expectExceptionObject(new InvalidArgumentException('The parseExcludes() method expects a string or an array. integer given'));

$manager = new Manager();

$manager->parseExcludes(99);
Expand Down
25 changes: 9 additions & 16 deletions test/ParamBagTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace League\Fractal\Test;

use League\Fractal\ParamBag;
use LogicException;
use PHPUnit\Framework\TestCase;

class ParamBagTest extends TestCase
Expand Down Expand Up @@ -32,23 +33,19 @@ public function testArrayAccess()
$this->assertNull($params['totallymadeup']);
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Modifying parameters is not permitted
*/
public function testArrayAccessSetFails()
{
$this->expectExceptionObject(new LogicException('Modifying parameters is not permitted'));

$params = new ParamBag(['foo' => 'bar']);

$params['foo'] = 'someothervalue';
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Modifying parameters is not permitted
*/
public function testArrayAccessUnsetFails()
{
$this->expectExceptionObject(new LogicException('Modifying parameters is not permitted'));

$params = new ParamBag(['foo' => 'bar']);

unset($params['foo']);
Expand All @@ -64,23 +61,19 @@ public function testObjectAccess()
$this->assertTrue(isset($params->foo));
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Modifying parameters is not permitted
*/
public function testObjectAccessSetFails()
{
$this->expectExceptionObject(new LogicException('Modifying parameters is not permitted'));

$params = new ParamBag(['foo' => 'bar']);

$params->foo = 'someothervalue';
}

/**
* @expectedException \LogicException
* @expectedExceptionMessage Modifying parameters is not permitted
*/
public function testObjectAccessUnsetFails()
{
$this->expectExceptionObject(new LogicException('Modifying parameters is not permitted'));

$params = new ParamBag(['foo' => 'bar']);

unset($params->foo);
Expand Down
12 changes: 6 additions & 6 deletions test/ScopeTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace League\Fractal\Test;

use InvalidArgumentException;
use League\Fractal\Manager;
use League\Fractal\Pagination\Cursor;
use League\Fractal\Resource\Collection;
Expand Down Expand Up @@ -222,12 +223,11 @@ public function testIsExcluded()
$this->assertTrue($scope->isExcluded('baz.bart'));
}

/**
* @expectedException \InvalidArgumentException
*/
public function testScopeRequiresConcreteImplementation()
{
$manager = new Manager();
$this->expectException(InvalidArgumentException::class);

$manager = new Manager();
$manager->parseIncludes('book');

$resource = Mockery::mock('League\Fractal\Resource\ResourceAbstract', [
Expand Down Expand Up @@ -382,11 +382,11 @@ public function testRunAppropriateTransformerWithCollection()

/**
* @covers \League\Fractal\Scope::executeResourceTransformers
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Argument $resource should be an instance of League\Fractal\Resource\Item or League\Fractal\Resource\Collection
*/
public function testCreateDataWithClassFuckKnows()
{
$this->expectExceptionObject(new InvalidArgumentException('Argument $resource should be an instance of League\Fractal\Resource\Item or League\Fractal\Resource\Collection'));

$manager = new Manager();

$transformer = Mockery::mock('League\Fractal\TransformerAbstract')->makePartial();
Expand Down
9 changes: 4 additions & 5 deletions test/Serializer/JsonApiSerializerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace League\Fractal\Test\Serializer;

use InvalidArgumentException;
use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
Expand Down Expand Up @@ -1827,13 +1828,11 @@ public function testSerializingCollectionResourceWithLinksForHasManyRelationship
$this->assertSame($expectedJson, $scope->toJson());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage JSON API resource objects MUST have a valid id
*/
public function testExceptionThrownIfResourceHasNoId()
{
$bookData = [
$this->expectExceptionObject(new InvalidArgumentException('JSON API resource objects MUST have a valid id'));

$bookData = [
'title' => 'Foo',
'year' => '1991',
];
Expand Down
12 changes: 8 additions & 4 deletions test/TransformerAbstractTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php namespace League\Fractal\Test;

use BadMethodCallException;
use Exception;
use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
use League\Fractal\Resource\Item;
Expand Down Expand Up @@ -97,10 +99,11 @@ public function testProcessEmbeddedResourcesNoDefaultIncludes()
/**
* @covers \League\Fractal\TransformerAbstract::processIncludedResources
* @covers \League\Fractal\TransformerAbstract::callIncludeMethod
* @expectedException \BadMethodCallException
*/
public function testProcessEmbeddedResourcesInvalidAvailableEmbed()
{
$this->expectException(BadMethodCallException::class);

$transformer = m::mock('League\Fractal\TransformerAbstract')->makePartial();

$manager = new Manager();
Expand All @@ -116,10 +119,11 @@ public function testProcessEmbeddedResourcesInvalidAvailableEmbed()
/**
* @covers \League\Fractal\TransformerAbstract::processIncludedResources
* @covers \League\Fractal\TransformerAbstract::callIncludeMethod
* @expectedException \BadMethodCallException
*/
public function testProcessEmbeddedResourcesInvalidDefaultEmbed()
{
$this->expectException(BadMethodCallException::class);

$transformer = m::mock('League\Fractal\TransformerAbstract')->makePartial();

$manager = new Manager();
Expand Down Expand Up @@ -228,11 +232,11 @@ public function testProcessIncludedAvailableResourcesEmptyEmbed()

/**
* @covers \League\Fractal\TransformerAbstract::callIncludeMethod
* @expectedException \Exception
* @expectedExceptionMessage Invalid return value from League\Fractal\TransformerAbstract::includeBook().
*/
public function testCallEmbedMethodReturnsCrap()
{
$this->expectExceptionObject(new Exception('Invalid return value from League\Fractal\TransformerAbstract::includeBook().'));

$manager = new Manager();
$manager->parseIncludes('book');
$transformer = m::mock('League\Fractal\TransformerAbstract[transform]');
Expand Down