From 16154a73068ea5b18ce7596709f4c21fca577dc1 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 6 Dec 2007 13:31:22 -0500 Subject: [PATCH] Unit test updates * UnitTest/ApiTest.php --- UnitTest/ApiTest.php | 46 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/UnitTest/ApiTest.php b/UnitTest/ApiTest.php index bf63976..08db303 100644 --- a/UnitTest/ApiTest.php +++ b/UnitTest/ApiTest.php @@ -43,6 +43,27 @@ class ApiTest extends PHPUnit_Framework_TestCase $this->fixture = null; } + public function testFailInsert() + { + try + { + $this->fixture->insert(); + $this->fail('exception expected'); + } + catch (ApiException $e) + { + $i = 0; + foreach ($e->getExceptions() AS $exc) + { + if ($exc instanceof FieldException) + { + $i++; + } + } + $this->assertEquals(sizeof($e->getExceptions()), $i); + } + } + public function testInsert() { $this->fixture->set('atext', 'moocow'); @@ -51,7 +72,14 @@ class ApiTest extends PHPUnit_Framework_TestCase $this->fixture->set('abool', true); $this->fixture->set('aint', 3); $this->fixture->set('afloat', 2.53); - $this->fixture->insert(); + try + { + $this->fixture->insert(); + } + catch (Exception $e) + { + $this->fail('unexpected exception'); + } } public function testMissingFields() @@ -79,6 +107,14 @@ class ApiTest extends PHPUnit_Framework_TestCase $this->fixture->setCondition('aint = 3'); $this->assertEquals('aint = 3', $this->fixture->T_getCondition()); + + try + { + $this->fixture->setCondition(array('__noexist__')); + $this->fail('exception expected'); + } + catch (Exception $e) + {} } } @@ -86,12 +122,12 @@ class TestApiFixture extends BSApi { protected $fields = array( 'id' => array(TYPE_UINT, REQ_AUTO), - 'atext' => array(TYPE_STR, REQ_YES), - 'avarchar' => array(TYPE_STR, REQ_YES), - 'abin' => array(TYPE_BIN, REQ_YES), + 'atext' => array(TYPE_STR, REQ_NO), + 'avarchar' => array(TYPE_STR, REQ_NO), + 'abin' => array(TYPE_BIN, REQ_NO), 'abool' => array(TYPE_BOOL, REQ_YES), 'aint' => array(TYPE_INT, REQ_YES), - 'afloat' => array(TYPE_FLOAT, REQ_YES) + 'afloat' => array(TYPE_FLOAT, REQ_NO) ); protected $table = 'apitest'; -- 2.22.5