protected function doCreate(RecordInterface $record, Version $version) { $this->testCase->assertEquals(3, $record->getUserId()); $this->testCase->assertEquals('test', $record->getTitle()); $this->testCase->assertInstanceOf('DateTime', $record->getDate()); return array('success' => true, 'message' => 'You have successful create a record'); }
protected function assertRecord(RecordInterface $record) { // check available fields $this->assertTrue($record->getRecordInfo()->hasField('id')); $this->assertTrue($record->getRecordInfo()->hasField('title')); $this->assertTrue($record->getRecordInfo()->hasField('active')); $this->assertTrue($record->getRecordInfo()->hasField('disabled')); $this->assertTrue($record->getRecordInfo()->hasField('count')); $this->assertTrue($record->getRecordInfo()->hasField('rating')); $this->assertFalse($record->getRecordInfo()->hasField('foobar')); $this->assertFalse($record->getRecordInfo()->hasField('foo')); if ($this->canDetermineType()) { $this->assertEquals(1, $record->getId()); $this->assertEquals('foobar', $record->getTitle()); $this->assertTrue($record->getActive()); $this->assertFalse($record->getDisabled()); $this->assertEquals(12, $record->getCount()); $this->assertEquals(12.45, $record->getRating()); $this->assertInternalType('integer', $record->getId()); $this->assertInternalType('string', $record->getTitle()); $this->assertInternalType('boolean', $record->getActive()); $this->assertInternalType('boolean', $record->getDisabled()); $this->assertInternalType('integer', $record->getCount()); $this->assertInternalType('float', $record->getRating()); $this->assertInstanceOf('DateTime', $record->getDate()); } else { $this->assertEquals('1', $record->getId()); $this->assertEquals('foobar', $record->getTitle()); // the json reader returns the real php type the xml reader returns // the string true or false $this->assertTrue($record->getActive() === true || $record->getActive() === 'true'); $this->assertTrue($record->getDisabled() === false || $record->getDisabled() === 'false'); $this->assertEquals('12', $record->getCount()); $this->assertEquals('12.45', $record->getRating()); $this->assertEquals('2014-01-01T12:34:47+01:00', $record->getDate()); } if ($this->canImportComplexRecord()) { $this->assertInstanceOf('PSX\\Data\\Record\\Importer\\Test\\Person', $record->getPerson()); $this->assertEquals('Foo', $record->getPerson()->getTitle()); $this->assertEquals(true, is_array($record->getTags())); $this->assertEquals(3, count($record->getTags())); $this->assertEquals('bar', $record->getTags()[0]); $this->assertEquals('foo', $record->getTags()[1]); $this->assertEquals('test', $record->getTags()[2]); $this->assertEquals(true, is_array($record->getEntry())); $this->assertEquals(3, count($record->getEntry())); $this->assertEquals('bar', $record->getEntry()[0]->getTitle()); $this->assertEquals('foo', $record->getEntry()[1]->getTitle()); $this->assertEquals('test', $record->getEntry()[2]->getTitle()); foreach ($record->getEntry() as $entry) { $this->assertInstanceOf('PSX\\Data\\Record\\Importer\\Test\\Entry', $entry); } $this->assertInstanceOf('stdClass', $record->getToken()); $this->assertEquals('bar', $record->getToken()->value); $this->assertInstanceOf('PSX\\Url', $record->getUrl()); $this->assertEquals('http://google.com', $record->getUrl()->__toString()); } }
/** * Checks whether the data we received as post is converted to the right * types * * @param \PHPUnit_Framework_TestCase $testCase * @param \PSX\Data\RecordInterface $record */ public static function assertRecord(\PHPUnit_Framework_TestCase $testCase, RecordInterface $record) { $testCase->assertInternalType('array', $record->getArray()); $testCase->assertEquals(1, count($record->getArray())); $testCase->assertEquals(['bar'], $record->getArray()); $testCase->assertInternalType('array', $record->getArrayComplex()); $testCase->assertEquals(2, count($record->getArrayComplex())); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayComplex()[0]); $testCase->assertEquals(['foo' => 'bar'], $record->getArrayComplex()[0]->getRecordInfo()->getFields()); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayComplex()[1]); $testCase->assertEquals(['foo' => 'foo'], $record->getArrayComplex()[1]->getRecordInfo()->getFields()); $testCase->assertInternalType('array', $record->getArrayChoice()); $testCase->assertEquals(3, count($record->getArrayChoice())); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[0]); $testCase->assertEquals(['foo' => 'baz'], $record->getArrayChoice()[0]->getRecordInfo()->getFields()); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[1]); $testCase->assertEquals(['bar' => 'bar'], $record->getArrayChoice()[1]->getRecordInfo()->getFields()); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getArrayChoice()[2]); $testCase->assertEquals(['foo' => 'foo'], $record->getArrayChoice()[2]->getRecordInfo()->getFields()); $testCase->assertInternalType('boolean', $record->getBoolean()); $testCase->assertEquals(true, $record->getBoolean()); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getChoice()); $testCase->assertEquals(['foo' => 'bar'], $record->getComplex()->getRecordInfo()->getFields()); $testCase->assertInstanceOf('PSX\\Data\\RecordInterface', $record->getComplex()); $testCase->assertEquals(['foo' => 'bar'], $record->getComplex()->getRecordInfo()->getFields()); $testCase->assertInstanceOf('PSX\\DateTime\\Date', $record->getDate()); $testCase->assertEquals('2015-05-01', $record->getDate()->format('Y-m-d')); $testCase->assertInstanceOf('PSX\\DateTime', $record->getDateTime()); $testCase->assertEquals('2015-05-01T13:37:14Z', $record->getDateTime()->format('Y-m-d\\TH:i:s\\Z')); $testCase->assertInstanceOf('PSX\\DateTime\\Duration', $record->getDuration()); $testCase->assertEquals('000100000000', $record->getDuration()->format('%Y%M%D%H%I%S')); $testCase->assertInternalType('float', $record->getFloat()); $testCase->assertEquals(13.37, $record->getFloat()); $testCase->assertInternalType('integer', $record->getInteger()); $testCase->assertEquals(7, $record->getInteger()); $testCase->assertInternalType('string', $record->getString()); $testCase->assertEquals('bar', $record->getString()); $testCase->assertInstanceOf('PSX\\DateTime\\Time', $record->getTime()); $testCase->assertEquals('13:37:14', $record->getTime()->format('H:i:s')); }
protected function doCreate(RecordInterface $record, Version $version) { $this->testCase->assertEquals(3, $record->getUserId()); $this->testCase->assertEquals('test', $record->getTitle()); $this->testCase->assertInstanceOf('DateTime', $record->getDate()); }