public function testToArray()
 {
     $object = new stdClass();
     $object->foo = 'bar';
     $object->baz = new stdClass();
     $object->baz->bat = 'bazbat';
     $expected = ObjectUtils::toArray($object);
     $this->trait->setProxy($object);
     $this->assertSame($expected, $this->trait->toArray());
 }
Пример #2
0
    public function testTransformKeys()
    {
        $object = <<<OBJ
        {
            "first-name": "Frankie",
            "surname": "Manning",
            "meta": {
                "created-at": "2015-01-01",
                "updated-at": "2015-02-01"
            },
            "associates": [
                {
                    "first-name": "Ella",
                    "surname": "Fitzgerald"
                },
                {
                    "first-name": "Chick",
                    "surname": "Webb"
                }
            ]
        }
OBJ;
        $expected = <<<OBJ
        {
            "first_name": "Frankie",
            "surname": "Manning",
            "meta": {
                "created_at": "2015-01-01",
                "updated_at": "2015-02-01"
            },
            "associates": [
                {
                    "first_name": "Ella",
                    "surname": "Fitzgerald"
                },
                {
                    "first_name": "Chick",
                    "surname": "Webb"
                }
            ]
        }
OBJ;
        $object = $this->toObject($object);
        $actual = ObjectUtils::transformKeys($object, function ($key) {
            return is_int($key) ? $key : str_replace('-', '_', $key);
        });
        $this->assertEquals($this->toObject($expected), $actual);
        $this->assertSame($object, $actual);
        $this->assertSame($object->meta, $actual->meta);
    }
Пример #3
0
 /**
  * Assert that the resource's relationships contains the provided subset.
  *
  * @param object|array $expected
  * @param string|null $message
  * @return $this
  */
 public function assertRelationshipsSubset($expected, $message = null)
 {
     $expected = ObjectUtils::toArray($expected);
     $actual = ObjectUtils::toArray($this->getRelationships() ?: []);
     $message = $message ? $this->withIndex($message) : $this->withIndex('Unexpected resource relationships') . ': ' . json_encode($actual);
     PHPUnit::assertArraySubset($expected, $actual, $message);
     return $this;
 }
Пример #4
0
 /**
  * @return array
  */
 public function toArray()
 {
     return ObjectUtils::toArray($this->getProxy());
 }