Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
Fix tests, improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
qurben committed Jan 11, 2019
1 parent 37a4966 commit 02314cc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 42 deletions.
36 changes: 0 additions & 36 deletions src/Entity/DynamicEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,4 @@ public function getAttributeDefinition($attribute_name) {
public function getPrimaryKey() {
return array_values($this->definition->primary_key);
}

/**
* @param string $attribute
* @param mixed $value
*/
public function __set($attribute, $value) {
$this->$attribute = $value;
}

/**
* @param string $attribute
* @return mixed
*/
public function __get($attribute) {
if (property_exists(get_class($this), $attribute)) {
return $this->$attribute;
}
return null;
}

/**
* @param string $attribute
* @return bool
*/
public function __isset($attribute) {
return $this->__get($attribute) !== null;
}

/**
* @param string $attribute
*/
public function __unset($attribute) {
if ($this->__isset($attribute)) {
unset($this->$attribute);
}
}
}
5 changes: 1 addition & 4 deletions tests/Entity/PersistentEntityComputedAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ public function testComputedJsonSerialize() {
public function testWrongComputedAttribute() {
$entity = new MyComputedAttributeEntity();

$this->expectExceptionMessage('Attribute not found: wrong_attribute');
$this->expectException(\CsrDelft\Orm\Exception\CsrOrmException::class);

$entity->wrong_attribute;
$this->assertEquals(null, $entity->wrong_attribute);
}

public function testGetComputedAttributes() {
Expand Down
41 changes: 39 additions & 2 deletions tests/Persistence/DatabaseTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
<?php /** @noinspection SqlNoDataSourceInspection */

use CsrDelft\Orm\Exception\CsrOrmException;
use CsrDelft\Orm\Persistence\Database;

require_once 'MySqlDatabaseTestCase.php';
Expand All @@ -18,6 +20,9 @@ protected function getDataSet() {
return $this->createFlatXMLDataSet(__DIR__ . '/../resources/DatabaseTest.xml');
}

/**
* @throws CsrOrmException
*/
public function testSqlSelect() {
$database = new Database($this->getConnection()->getConnection());

Expand All @@ -41,6 +46,9 @@ public function testSqlInsert() {
$this->assertEquals(['user' => 'John Doe'], $dataset->getRow($dataset->getRowCount() - 1));
}

/**
* @throws CsrOrmException
*/
public function testSqlExists() {
$database = new Database($this->getConnection()->getConnection());

Expand All @@ -67,6 +75,35 @@ public function testSqlUpdate() {
$this->assertEquals(['user' => 'pete'], $dataset->getRow(0));
}

/**
* @throws CsrOrmException
* @throws Exception
*/
public function testInsertMultiple() {
$database = new Database($this->getConnection()->getConnection());
$dataset = $this->getConnection()->createQueryTable('guestbook', 'SELECT user FROM guestbook');

$database->sqlInsertMultiple('guestbook', [['user', 'id'], ['pete', 3], ['jan', 4]]);

$this->assertEquals(4, $dataset->getRowCount());
}

/**
* @throws CsrOrmException
* @throws Exception
*/
public function testInsertMultipleReplace() {
$database = new Database($this->getConnection()->getConnection());
$dataset = $this->getConnection()->createQueryTable('guestbook', 'SELECT user FROM guestbook');

$database->sqlInsertMultiple('guestbook', [['user', 'id'], ['pete', 1], ['jan', 4]], true);

$this->assertEquals(3, $dataset->getRowCount());
}

/**
* @throws CsrOrmException
*/
public function testSqlDelete() {
$database = new Database($this->getConnection()->getConnection());
$dataset = $this->getConnection()->createQueryTable('guestbook', 'SELECT * FROM guestbook');
Expand Down Expand Up @@ -115,7 +152,7 @@ public function testTransactionRollback() {
throw new MyException("testException");
});
$this->fail("Exception expected");
} catch (MyException $ex) {
} /** @noinspection PhpRedundantCatchClauseInspection */ catch (MyException $ex) {
$this->assertEquals("testException", $ex->getMessage(), 'Exception is rethrown');
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Persistence/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,10 @@ public function testInterpolateQuery() {
);
}

public function testBuildEnum() {
$query_builder = new QueryBuilder();

$this->assertEquals("enum('a','b')", $query_builder->buildEnum(['a', 'b']));
}

}

0 comments on commit 02314cc

Please sign in to comment.