/** * @test * @dataProvider provideTestUsers */ public function it_adds_a_user_to_existing_file(TestUserCollection $users) { if (!is_writable(sys_get_temp_dir())) { $this->markTestSkipped(sprintf("Temp dir %s is not writable", sys_get_temp_dir())); } $this->fileTypeAdapter->writeDataOfType($this->tempFile, $users); $donaldDuck = TestUser::fromNativeValue(['id' => 3, 'name' => 'Donald Duck', 'age' => 57]); $this->fileTypeAdapter->writeDataOfType($this->tempFile, $donaldDuck); $readUsersData = $this->fileTypeAdapter->readDataForType($this->tempFile, $users->prototype()); $readUsers = TestUserCollection::fromNativeValue($readUsersData); $this->assertEquals(3, count($readUsers->value())); $this->assertEquals(['John Doe', 'Max Mustermann', 'Donald Duck'], array_map(function (TestUser $user) { return $user->property('name')->value(); }, $readUsers->value())); }
/** * @test */ public function it_reads_data_for_user_from_json() { $data = $this->fileTypeAdapter->readDataForType($this->getTestDataPath() . 'testuser_john_doe.json', TestUser::prototype()); $user = TestUser::fromNativeValue($data); $this->assertEquals('John Doe', $user->property('name')->value()); }