/** * @test * @depends it_handles_basic_retrieval_operations */ function it_handles_basic_manipulation_operations() { // update existing $someId = $this->repository->findBy(self::UNIQUE_FIELD, '999')->id; $this->assertNotEmpty($someId, "Did not get a valid Model's id from the findBy(unique_field) result"); $this->repository->update(['name' => 'changed it!'], $someId); $this->assertEquals('changed it!', $this->repository->findBy(self::UNIQUE_FIELD, '999')->name, "Change did not apply after update()"); // create new $model = $this->repository->create([self::UNIQUE_FIELD => '313', 'name' => 'New Model']); $this->assertInstanceOf(Model::class, $model, "Create() response is not a Model"); $this->assertNotEmpty($model->id, "Model does not have an id (likely story)"); $this->seeInDatabase(static::TABLE_NAME, ['id' => $model->id, self::UNIQUE_FIELD => '313', 'name' => 'New Model']); $this->assertEquals(4, $this->repository->count(), "Total count after creating new does not match"); // delete $this->assertEquals(1, $this->repository->delete($model->id), "Delete() call did not return succesful count"); $this->assertEquals(3, $this->repository->count(), "Total count after deleting does not match"); $this->notSeeInDatabase(static::TABLE_NAME, ['id' => $model->id]); unset($model); }