public function testUpdatePointHasCorrectSql()
 {
     $this->model->exists = true;
     $this->model->point = new Point(2, 4);
     $this->model->save();
     $this->assertContains("ST_GeogFromText('POINT(4 2)')", $this->queries[0]);
 }
Esempio n. 2
0
 /**
  * @depends testDeleteOldTestData
  */
 public function testCreateEntity()
 {
     // Creating entity...
     $testEntity = TestModel::factory();
     $this->assertThat($testEntity, $this->logicalOr($this->isInstanceOf('TestModel'), $this->isInstanceOf('\\Sciactive\\HookOverride_TestModel')));
     // Saving entity...
     $testEntity->name = 'Entity Test ' . time();
     $testEntity->null = null;
     $testEntity->string = 'test';
     $testEntity->array = ['full', 'of', 'values', 500];
     $testEntity->match = "Hello, my name is Edward McCheese. It is a pleasure to meet you. As you can see, I have several hats of the most pleasant nature.\n\nThis one's email address is nice_hat-wednesday+newyork@im-a-hat.hat.\nThis one's phone number is (555) 555-1818.\nThis one's zip code is 92064.";
     $testEntity->number = 30;
     $this->assertTrue($testEntity->save());
     $entity_guid = $testEntity->guid;
     $entity_reference_test = new TestModel();
     $entity_reference_test->string = 'wrong';
     $this->assertTrue($entity_reference_test->save());
     $entity_reference_guid = $entity_reference_test->guid;
     $testEntity->reference = $entity_reference_test;
     $testEntity->ref_array = [0 => ['entity' => $entity_reference_test]];
     $this->assertTrue($testEntity->save());
     $entity_reference_test->test = 'good';
     $this->assertTrue($entity_reference_test->save());
     $testEntity = Nymph::getEntity(['class' => 'TestModel'], $entity_guid);
     $this->assertThat($testEntity, $this->logicalOr($this->isInstanceOf('TestModel'), $this->isInstanceOf('\\Sciactive\\HookOverride_TestModel')));
     return ['entity' => $testEntity, 'refGuid' => $entity_reference_guid];
 }
 public function testSaveRecord()
 {
     $seed = $this->seed();
     $seedId = array_get($seed, 'id.S');
     $newName = 'New Name to be saved';
     $this->testModel = $this->testModel->find($seedId);
     $this->testModel->name = $newName;
     $this->testModel->save();
     $query = ['TableName' => $this->testModel->getTable(), 'Key' => ['id' => ['S' => $seedId]]];
     $record = $this->dynamoDbClient->getItem($query)->toArray();
     $this->assertEquals($newName, array_get($record, 'Item.name.S'));
 }
Esempio n. 4
0
 public function testHydrate()
 {
     $test = new TestModel(['id' => 1, 'first_name' => 'john', 'last_name' => 'smith', 'age' => 29, 'secret' => 'foobar'], true);
     // test construct / hydration
     $this->assertEquals(1, $test->id);
     $this->assertEquals('john', $test->first_name);
     $this->assertEquals('smith', $test->last_name);
     $this->assertEquals(29, $test->age);
     $this->assertEquals('foobar', $test->secret);
     $this->assertFalse($test->isNew());
     // test revert
     $test->age = 34;
     $this->assertEquals(34, $test->age);
     $this->assertEquals(29, $test->revert()->age);
     // test save
     $test->age = 34;
     $this->assertEquals(34, $test->age);
     $test->save();
     $this->assertEquals(34, $test->revert()->age);
     // test sync
     $this->assertEquals(['id' => 1, 'first_name' => 'john', 'last_name' => 'smith', 'age' => 27, 'secret' => 'foobar2'], $test->sync()->toArray());
     // test not fillable column
     $test->id = 20;
     $this->assertEquals(1, $test->id);
     // test delete
     $this->assertEquals(['id' => null, 'first_name' => null, 'last_name' => null, 'age' => null, 'secret' => null], $test->delete()->toArray());
 }
Esempio n. 5
0
 public function testDBFunctions()
 {
     $db = new DB_Interface();
     foreach ($models = $db->show('testmodel') as $model) {
         $model->delete();
     }
     $tests = $db->show('testmodel');
     $this->assertEquals(count($tests), 0);
     for ($i = 1; $i <= 10; $i++) {
         $model = new TestModel();
         $model->name = 'This is a test';
         $model->price = 1;
         $model->size = '5';
         $model->save();
         $tests = $db->show('testmodel');
         $this->assertEquals(count($tests), $i);
     }
     $models = $db->show('testmodel');
     for ($i = 0; $i < count($models); $i++) {
         $model = $models[$i];
         $model->delete();
         $tests = $db->show('testmodel');
         $this->assertEquals(count($tests), count($models) - $i - 1);
     }
 }
Esempio n. 6
0
 public function testSingleAfterSaveCall()
 {
     \PHPModelDemo\ModelDemoConfig::init();
     $test_obj = new TestModel();
     $test_obj->setAfterSaveCounter(0);
     $test_obj->save();
     $this->assertEquals(1, $test_obj->getAfterSaveCounter());
 }
 /**
  * @param $connection
  *
  * @dataProvider connectionsProvider
  */
 function testDba($connection)
 {
     $capsule = $this->setConnection($connection);
     $capsule->connection()->enableQueryLog();
     $table = new TestModel();
     $table->name = 'One';
     $table->save();
     /** @var \Fnp\Eloquent\Grammar $grammar */
     $grammar = $this->config[$connection]['grammar'];
     $quote = function ($name) use($connection) {
         $quote = $this->config[$connection]['quote'];
         return $quote . $name . $quote;
     };
     $timestamp = $grammar::timestamp();
     $generatedSql = $capsule->connection()->getQueryLog()[0]['query'];
     $pattern = '#insert into .test_table. \\(.name., .updated_at., .created_at.\\) values \\(\\?, (.*), (.*)\\)#';
     $match = [];
     $result = preg_match($pattern, $generatedSql, $match);
     $this->assertEquals($match[1], $timestamp);
     $this->assertEquals($match[2], $timestamp);
 }
Esempio n. 8
0
 public function testORM()
 {
     include_once __DIR__ . "/../libs/TestModel.php";
     //@\PHPPE\DS::db("mysql:host=localhost;dbname=testdb");
     @(include_once "vendor/phppe/Core/libs/ds_mysql.php");
     \PHPPE\DS::close();
     \PHPPE\DS::db("sqlite::memory:");
     $testModel = new TestModel();
     $this->assertEquals('a:4:{i:0;a:3:{s:2:"id";s:1:"1";s:4:"name";s:5:"first";s:8:"parentId";s:1:"0";}i:1;a:3:{s:2:"id";s:1:"2";s:4:"name";s:6:"second";s:8:"parentId";s:1:"0";}i:2;a:3:{s:2:"id";s:1:"3";s:4:"name";s:5:"third";s:8:"parentId";s:1:"1";}i:3;a:3:{s:2:"id";s:1:"4";s:4:"name";s:6:"fourth";s:8:"parentId";s:1:"0";}}', serialize($testModel->find()), "ORM find #1");
     $this->assertEquals('a:3:{i:0;a:3:{s:2:"id";s:1:"1";s:4:"name";s:5:"first";s:8:"parentId";s:1:"0";}i:1;a:3:{s:2:"id";s:1:"2";s:4:"name";s:6:"second";s:8:"parentId";s:1:"0";}i:2;a:3:{s:2:"id";s:1:"4";s:4:"name";s:6:"fourth";s:8:"parentId";s:1:"0";}}', serialize($testModel->find(0, "parentId=?")), "ORM find #2");
     $this->assertEquals('a:1:{i:0;a:3:{s:2:"id";s:1:"3";s:4:"name";s:5:"third";s:8:"parentId";s:1:"1";}}', serialize($testModel->find(1, "parentId=?")), "ORM find #3");
     $this->assertEquals(5, $testModel->save(), "ORM save insert");
     $this->assertEquals(5, $testModel->id, "ORM save id");
     $testModel->name = "sssss";
     $this->assertEquals(5, $testModel->save(), "ORM save update");
     $testModel->id = 6;
     $this->assertFalse($testModel->save(), "ORM save update fail");
     $this->assertFalse($testModel->load(7), "ORM load fail");
     $this->assertEquals(3, $testModel->load(3), "ORM load success");
     $this->assertEquals(3, $testModel->id, "ORM load id");
     $testModel->name = "sssss";
     $this->assertEquals(3, $testModel->load(3), "ORM load reload");
     $this->assertNotEquals("sssss", $testModel->name, "ORM load name");
     $testModel = new TestModel(1);
     $this->assertEquals(1, $testModel->id, "Creating with id");
     \PHPPE\DS::close();
     $wasExc = false;
     try {
         $testModel->save();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "save exception no ds");
     $testModel = new TestModel(['id' => 1, 'name' => 'one']);
     $this->assertEquals(1, $testModel->id, "Creating with fields");
     $testModel = new BadModel();
     $wasExc = false;
     try {
         $testModel->save();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "save exception no table");
     $wasExc = false;
     try {
         $testModel->find();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "find exception");
     $wasExc = false;
     try {
         $testModel->load();
     } catch (\Exception $e) {
         $wasExc = true;
     }
     $this->assertTrue($wasExc, "load exception");
 }
Esempio n. 9
0
 /** @test */
 public function cannotSaveImmutableModel()
 {
     $model = new TestModel();
     $this->setExpectedException('RuntimeException');
     $model->save();
 }
 public function testPreservationOfWasModifiedProperty()
 {
     $origValues = array(101, '*****@*****.**');
     $testObject = new TestModel();
     $this->assertEquals(false, $testObject->wasModified());
     $testObject->hydrate($origValues);
     $testObject->setEmailAddress('*****@*****.**');
     $this->assertEquals(true, $testObject->wasModified());
     $testObject->save();
     $this->assertEquals(true, $testObject->wasModified());
     $testObject->delete();
     $this->assertEquals(true, $testObject->wasModified());
 }
Esempio n. 11
0
 public function testCanFilterWebhooks()
 {
     $webhook = new Webhook();
     $webhook->tenant_id = 1;
     $webhook->url = "http://test.foo/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $webhook = new Webhook();
     $webhook->tenant_id = 2;
     $webhook->url = "http://test.bar/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $webhook = new Webhook();
     $webhook->tenant_id = 3;
     $webhook->url = "http://test.baz/saved";
     $webhook->event = "eloquent.saved: TestModel";
     $webhook->save();
     $client = m::mock("GuzzleHttp\\Client");
     $client->shouldReceive("postAsync")->once();
     $client->shouldReceive("postAsync")->with("http://test.bar/saved", m::any());
     $config = m::mock("stdClass");
     $config->shouldReceive("get")->with("captain_hook.filter", null)->andReturn(function ($item) {
         return $item->tenant_id == 2;
     });
     $provider = $this->app->getProvider("Mpociot\\CaptainHook\\CaptainHookServiceProvider");
     $provider->setClient($client);
     $provider->setConfig($config);
     $obj = new TestModel();
     $obj->name = "Test";
     $obj->save();
 }