Skip to content

Commit dfcb0d2

Browse files
committed
Minor adjustments and clarifying some tests for future reference.
Signed-off-by: Jason Lewis <[email protected]>
1 parent ed55d11 commit dfcb0d2

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

src/Transformer/Factory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ protected function boundByContract($class)
177177
{
178178
if ($this->isCollection($class))
179179
{
180-
return is_object($class->first()) and $class->first() instanceof TransformableInterface;
180+
$class = $class->first();
181181
}
182182

183183
return is_object($class) and $class instanceof TransformableInterface;

tests/TransformerFactoryTest.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ public function testRegisterTransformer()
2828

2929
public function testDeterminingIfResponseIsTransformable()
3030
{
31-
$this->assertFalse($this->transformerFactory->transformableResponse(['foo' => 'bar']));
32-
$this->assertFalse($this->transformerFactory->transformableResponse(new stdClass));
33-
$this->assertFalse($this->transformerFactory->transformableResponse('Foo'));
34-
$this->assertFalse($this->transformerFactory->transformableResponse(1));
35-
$this->assertFalse($this->transformerFactory->transformableResponse(true));
36-
$this->assertFalse($this->transformerFactory->transformableResponse(false));
37-
$this->assertFalse($this->transformerFactory->transformableResponse(31.1));
38-
$this->assertFalse($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Foo, new Foo])));
31+
$this->assertFalse($this->transformerFactory->transformableResponse(['foo' => 'bar']), 'Testing that an array is not transformable.');
32+
$this->assertFalse($this->transformerFactory->transformableResponse(new stdClass), 'Testing that a class with no binding is not transformable.');
33+
$this->assertFalse($this->transformerFactory->transformableResponse('Foo'), 'Testing that a string with no binding is not transformable.');
34+
$this->assertFalse($this->transformerFactory->transformableResponse(1), 'Testing that an integer is not transformable.');
35+
$this->assertFalse($this->transformerFactory->transformableResponse(true), 'Testing that a boolean is not transformable.');
36+
$this->assertFalse($this->transformerFactory->transformableResponse(false), 'Testing that a boolean is not transformable.');
37+
$this->assertFalse($this->transformerFactory->transformableResponse(31.1), 'Testing that a float is not transformable.');
38+
$this->assertFalse($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Foo, new Foo])), 'Testing that a collection with instances that have no binding are not transformable.');
3939
$this->transformerFactory->transform('Foo', 'FooTransformerStub');
40-
$this->assertTrue($this->transformerFactory->transformableResponse('Foo'));
41-
$this->assertTrue($this->transformerFactory->transformableResponse(new Bar));
42-
$this->assertTrue($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Bar, new Bar])));
40+
$this->assertTrue($this->transformerFactory->transformableResponse('Foo'), 'Testing that a string with a binding is transformable.');
41+
$this->assertTrue($this->transformerFactory->transformableResponse(new Bar), 'Testing that an instance that is bound by a contract is transformable.');
42+
$this->assertTrue($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Bar, new Bar])), 'Testing that a collection with instances bound by a contract are transformable.');
43+
$this->assertTrue($this->transformerFactory->transformableResponse(new Illuminate\Support\Collection([new Foo, new Foo])), 'Testing that a collection with instances that have a binding are transformable.');
4344
}
4445

4546

0 commit comments

Comments
 (0)