tests/Extensions/Issue169/IssueTest.php
/**
     * Test encoder will serialize into arrays.
     *
     * @see https://github.com/neomerx/json-api/issues/169
     */
Test encoder will serialize into arrays.
Test encoder will serialize into arrays .
public function testDataSerialization(): void
    {
        $author = Author::instance(9, 'Dan', 'Gebhardt');
        $encoder = CustomEncoder::instance(
            [
                Author::class => function ($factory) {
                    $schema = new AuthorSchema($factory);
                    $schema->removeRelationship(Author::LINK_COMMENTS);
                    return $schema;
                },
            ]
        );
        $actual = $encoder->serializeData($author);
        $expected = [
            'data' => [
                'type'       => 'people',
                'id'         => '9',
                'attributes' => [
                    'first_name' => 'Dan',
                    'last_name'  => 'Gebhardt',
                ],
                'links'      => [
                    'self' => '/people/9',
                ],
            ],
        ];
        $this->assertEquals($expected, $actual);
    }
public function testDataSerialization ( ) : void { $ author = Author :: instance ( 9 , 'Dan' , 'Gebhardt' ) ; $ encoder = CustomEncoder :: instance ( [ Author :: class => function ( $ factory ) { $ schema = new AuthorSchema ( $ factory ) ; $ schema -> removeRelationship ( Author :: LINK_COMMENTS ) ; return $ schema ; } , ] ) ; $ actual = $ encoder -> serializeData ( $ author ) ; $ expected = [ 'data' => [ 'type' => 'people' , 'id' => '9' , 'attributes' => [ 'first_name' => 'Dan' , 'last_name' => 'Gebhardt' , ] , 'links' => [ 'self' => '/people/9' , ] , ] , ] ; $ this -> assertEquals ( $ expected , $ actual ) ; }
Test encoder will serialize into arrays.
Test encoder will serialize into arrays .
/** @var CustomEncoder $encoder */