/** * When called will output a json string */ public function testWhenCalledWillOutputAJsonString() { $this->mock->expects($this->any())->method('toString')->will($this->returnValue('outputString')); $this->mock->expects($this->any())->method('toArray')->will($this->returnValue([])); $jsonFromString = $this->mock->toJson(0, 'string'); $jsonFromArray = $this->mock->toJson(0, 'array'); $decodedJsonFromString = json_decode($jsonFromString); $decodedJsonFromArray = json_decode($jsonFromArray); $this->assertInternalType('string', $jsonFromString); $this->assertInternalType('string', $jsonFromArray); $this->assertInternalType('string', $decodedJsonFromString); $this->assertInternalType('array', $decodedJsonFromArray); }
public function testDataFills() { $fake = $this->generateFakeData(); $instance = $this->rebuildTestInstance(); $property = new \ReflectionProperty($instance, 'attributes'); $property->setAccessible(true); $property->setValue($instance, ['name', 'name1', 'name2']); $property->setAccessible(false); foreach ($fake as $key => $value) { $instance->{$key} = $key === 'name2' ? new Collection() : null; } $instance->fill($fake); foreach ($fake as $key => $value) { if ($key !== 'name2') { $this->assertSame($fake[$key], $this->testInstance->{$key}); } else { $this->assertTrue($this->testInstance->name2->count() === 3); } } $this->assertSame($fake, $this->testInstance->toArray()); $this->assertSame($fake, $this->testInstance->toModel()); $this->assertSame(json_encode($fake), $this->testInstance->toJson()); }