From 190c6bb125447f83793d9437f1bea28feada910a Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:13:39 +0700 Subject: [PATCH 01/20] Cleaning up --- .../database/query_builder/insert_test.php | 5 ++--- .../database/query_builder/select_test.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/codeigniter/database/query_builder/insert_test.php b/tests/codeigniter/database/query_builder/insert_test.php index 53ce23c193e..8ba60e2421d 100644 --- a/tests/codeigniter/database/query_builder/insert_test.php +++ b/tests/codeigniter/database/query_builder/insert_test.php @@ -30,11 +30,10 @@ public function test_insert() // Do normal insert $this->assertTrue($this->db->insert('job', $job_data)); - $jobs = $this->db->get('job')->result_array(); - $job1 = $jobs[0]; + $job1 = $this->db->get('job')->row(); // Check the result - $this->assertEquals('Grocery Sales', $job1['name']); + $this->assertEquals('Grocery Sales', $job1->name); } diff --git a/tests/codeigniter/database/query_builder/select_test.php b/tests/codeigniter/database/query_builder/select_test.php index dbf432a7cc9..0d299ed16b2 100644 --- a/tests/codeigniter/database/query_builder/select_test.php +++ b/tests/codeigniter/database/query_builder/select_test.php @@ -41,10 +41,10 @@ public function test_select_min() { $job_min = $this->db->select_min('id') ->get('job') - ->result_array(); + ->row(); // Minimum id was 1 - $this->assertEquals('1', $job_min[0]['id']); + $this->assertEquals('1', $job_min->id); } // ------------------------------------------------------------------------ @@ -56,10 +56,10 @@ public function test_select_max() { $job_max = $this->db->select_max('id') ->get('job') - ->result_array(); + ->row(); // Maximum id was 4 - $this->assertEquals('4', $job_max[0]['id']); + $this->assertEquals('4', $job_max->id); } // ------------------------------------------------------------------------ @@ -71,10 +71,10 @@ public function test_select_avg() { $job_avg = $this->db->select_avg('id') ->get('job') - ->result_array(); + ->row(); // Average should be 2.5 - $this->assertEquals('2.5', $job_avg[0]['id']); + $this->assertEquals('2.5', $job_avg->id); } // ------------------------------------------------------------------------ @@ -86,10 +86,10 @@ public function test_select_sum() { $job_sum = $this->db->select_sum('id') ->get('job') - ->result_array(); + ->row(); // Sum of ids should be 10 - $this->assertEquals('10', $job_sum[0]['id']); + $this->assertEquals('10', $job_sum->id); } } \ No newline at end of file From 6e131cbd0a5243f29a5ad9f56c80715e534e4267 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 12:14:19 +0700 Subject: [PATCH 02/20] FROM clause API code-coverage --- .../database/query_builder/from_test.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/from_test.php diff --git a/tests/codeigniter/database/query_builder/from_test.php b/tests/codeigniter/database/query_builder/from_test.php new file mode 100644 index 00000000000..95ae4dfdbf3 --- /dev/null +++ b/tests/codeigniter/database/query_builder/from_test.php @@ -0,0 +1,51 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_simple() + { + $jobs = $this->db->from('job') + ->get() + ->result_array(); + + // Check items + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_from_with_where() + { + $job1 = $this->db->from('job') + ->where('id', 1) + ->get() + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + $this->assertEquals('Awesome job, but sometimes makes you bored', $job1->description); + } + +} \ No newline at end of file From 17f799e1017d1688a2890a1ba78e4f53d80af77e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Thu, 3 May 2012 15:15:40 +0700 Subject: [PATCH 03/20] Add user entity into schema skeleton --- tests/mocks/database/schema/skeleton.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index a3d5bac6539..fbd533bfb77 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -50,6 +50,24 @@ public static function init($driver) */ public static function create_tables() { + // User Table + static::$forge->add_field(array( + 'id' => array( + 'type' => 'INTEGER', + 'constraint' => 3, + ), + 'name' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), + 'email' => array( + 'type' => 'VARCHAR', + 'constraint' => 100, + ), + )); + static::$forge->add_key('id', TRUE); + static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); + // Job Table static::$forge->add_field(array( 'id' => array( @@ -77,6 +95,12 @@ public static function create_data() { // Job Data $data = array( + 'user' => array( + array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'), + array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), + array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), + array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), + ) 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'), From d6b41bb2659f959da01aee0ddb38bb4bce6cd4b6 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:05:22 +0700 Subject: [PATCH 04/20] JOIN clause API code-coverage --- .../database/query_builder/join_test.php | 38 +++++++++++++++++++ tests/mocks/database/schema/skeleton.php | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/database/query_builder/join_test.php diff --git a/tests/codeigniter/database/query_builder/join_test.php b/tests/codeigniter/database/query_builder/join_test.php new file mode 100644 index 00000000000..e05329d670a --- /dev/null +++ b/tests/codeigniter/database/query_builder/join_test.php @@ -0,0 +1,38 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_join_simple() + { + $job_user = $this->db->select('job.id as job_id, job.name as job_name, user.id as user_id, user.name as user_name') + ->from('job') + ->join('user', 'user.id = job.id') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals('1', $job_user[0]['job_id']); + $this->assertEquals('1', $job_user[0]['user_id']); + $this->assertEquals('Derek Jones', $job_user[0]['user_name']); + $this->assertEquals('Developer', $job_user[0]['job_name']); + } + +} \ No newline at end of file diff --git a/tests/mocks/database/schema/skeleton.php b/tests/mocks/database/schema/skeleton.php index fbd533bfb77..9ebd6e85fd2 100644 --- a/tests/mocks/database/schema/skeleton.php +++ b/tests/mocks/database/schema/skeleton.php @@ -100,7 +100,7 @@ public static function create_data() array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), - ) + ), 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), array('id' => 2, 'name' => 'Politician', 'description' => 'This is not really a job'), From 12f5475e2b279d1c2361ad5fc85bc2ba0d0f9033 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:46:39 +0700 Subject: [PATCH 05/20] WHERE clause API code-coverage --- .../database/query_builder/where_test.php | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/where_test.php diff --git a/tests/codeigniter/database/query_builder/where_test.php b/tests/codeigniter/database/query_builder/where_test.php new file mode 100644 index 00000000000..607eaa076fb --- /dev/null +++ b/tests/codeigniter/database/query_builder/where_test.php @@ -0,0 +1,144 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_simple_key_value() + { + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_key_value() + { + $jobs = $this->db->where('id !=', 1) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_associative_array() + { + $where = array('id >' => 2, 'name !=' => 'Accountant'); + $jobs = $this->db->where($where) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(1, count($jobs)); + + // Should be Musician + $job = current($jobs); + + $this->assertEquals('Musician', $job['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_custom_string() + { + $where = "id > 2 AND name != 'Accountant'"; + $jobs = $this->db->where($where) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(1, count($jobs)); + + // Should be Musician + $job = current($jobs); + + $this->assertEquals('Musician', $job['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_or() + { + $jobs = $this->db->where('name !=', 'Accountant') + ->or_where('id >', 3) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_in() + { + $jobs = $this->db->where_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_where_not_in() + { + $jobs = $this->db->where_not_in('name', array('Politician', 'Accountant')) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } + +} \ No newline at end of file From f78018ec6b081518e4be24934448862a31bda9f8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 15:53:55 +0700 Subject: [PATCH 06/20] LIKE clause API code-coverage --- .../database/query_builder/like_test.php | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/like_test.php diff --git a/tests/codeigniter/database/query_builder/like_test.php b/tests/codeigniter/database/query_builder/like_test.php new file mode 100644 index 00000000000..df98c713fde --- /dev/null +++ b/tests/codeigniter/database/query_builder/like_test.php @@ -0,0 +1,90 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_like() + { + $job1 = $this->db->like('name', 'veloper') + ->get('job') + ->row(); + + // Check the result + $this->assertEquals('1', $job1->id); + $this->assertEquals('Developer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_like() + { + $jobs = $this->db->like('name', 'ian') + ->or_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Developer', $jobs[0]['name']); + $this->assertEquals('Politician', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_not_like() + { + $jobs = $this->db->not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_or_not_like() + { + $jobs = $this->db->like('name', 'an') + ->or_not_like('name', 'veloper') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Accountant', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + } + +} \ No newline at end of file From 4e607b00b2c56b7fdcc5f1d1a290be2363c74a46 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:22:48 +0700 Subject: [PATCH 07/20] GROUP BY clause API code-coverage --- .travis.yml | 3 +- .../database/query_builder/group_test.php | 37 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/codeigniter/database/query_builder/group_test.php diff --git a/.travis.yml b/.travis.yml index 97ea0422dbd..971f62f38a5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,4 +25,5 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml branches: only: - develop - - master \ No newline at end of file + - master + - db-tests \ No newline at end of file diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php new file mode 100644 index 00000000000..ddb2d0d6a3f --- /dev/null +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -0,0 +1,37 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_group_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name HAVING SUM(id) > 2') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } + +} \ No newline at end of file From f7377abee2ef1e165a362edc9a1c650373a002ca Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 19:42:24 +0700 Subject: [PATCH 08/20] Trace error --- .../database/query_builder/group_test.php | 8 ++++---- tests/mocks/database/ci_test.sqlite | Bin 17408 -> 19456 bytes 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index ddb2d0d6a3f..dd248ae9a1e 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,16 @@ public function set_up() */ public function test_group_by() { - $jobs = $this->db->select('name') + $jobs = $this->db->select('job.name as job_name, job.id as job_id') ->from('job') - ->group_by('name HAVING SUM(id) > 2') + ->group_by('job_name HAVING SUM(job_id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['name']); - $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Accountant', $jobs[0]['job_name']); + $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index 86d868af250aa75827bb3a6b821b92a569472d3e..e4128b23f676b9a9d82582e390ad2d2a197fde32 100755 GIT binary patch delta 573 zcmZqZU~HJdI6+#_h=GAY7>JpHn2&*hv2mh~v9u9`?jspqCVK`J#uf&~7AA3KOXh13 zxUrFoaq?Z=-5~W73+J*h3o;l@Y&2xlnAoUN-zeF{$u2G`%Ge}Yl9-f}T3Vc11j0hj zL9UJ=t_mTJPCl**2_T^a1r06*g@nwM1cl7J5)ETb1wa1~1;0=qA03c*USe))f_E&0#GF9P0mOnpEC9s7pkd$vVpbq#0b+h2<^}8C ztRQiY87HxEf-vJE6%PC=H%^dc6acw^g*lIb`9AXw<_XMs8yn-8>lIj77*(}doHL3t zixqqmi%K%{l0j^T^8BKl6usp9Ts3AEMqPd8piEFer6@QmI41&qR#^n$Bh;xfu`nu| vGdX7DCZ=TOrDi3jBqEpyW%7(bW!j7`sYR*T3SPqbd8x%IAT~n9A`TV+xZ#~unsZIdjBA><1FzMF%TQ3IT<{|AN4MZMF?3HsFi~-@?c6HfB^%2q*;Z1cCjA$;NZLj6ywd zLOv^k$nmO_pRW3DZP^vgsjAN_8H z>L1ljHuhv%pOJxF;wOAhhBeAAQf|F_Qa8>_mN~GCo$%`(pYi1)rZrzqQ%Ym5mWNPN z1FmRr9e#(am{CC?pb)s{5HNu;!=M;|VqK@0CH!x}*Bbl@zroM&16;y_3JL**z$Qk( zwCHgMGkM;1(^!4rDPg8g4?db5l<36&7JR9}AMh(&f$!lPEU2ImPzY>F1X2b*)dpBe z3c8u3x^8q*21&|5@1%Od{{Ww8@DqH2i3$nB(KB~Z~8G`aa@-#$cWDeQu5Hl-8#pUcy5em2C_O1a6~`tyH1qMU9RJa0{nS? z!~>bkDQLLE%wT&2n~~?G>o3b7zam4wA=hW3Qsgvb$Qxn_W16|*2eL-|uipQ6FSp7o z1nxZq$O`Dk|0y=Cv0?TpyQDAc@4;bMy!Z6K4UJllv|dl8M@CrtP$Vj@Tykpo+ftY- z=F3H1&L1lkIactAp{*DnKUpq5SDc$Tw2z-WRpuwpmP(UDTjNj$cHdS{;Q!>8@^gjf z^K%nV9PGJMEXY1%o}N2Co1Z(!UnrjA6Haa4(7y538&>-15vDm_O}-Ysiu53D5l4Pf zwoynshtby7_STynjm$(NWD5KZ^=O0@12q~Xb4`ZTz*&wQ-{a-t%jJpO!Cs~QN%RYY zL`P}t97e;f-L1D$=}d;Thu1{630&$x>9(7dNNNXaGI(uh;Jyp@cRe0!YgW3D>9+)H zVkXKYqHS+I*k-Bp=qPKa5{&}im2^GOqY2dv)Z#y04?6#A!dDtx!_$91!bQxgpb$_9 zY+eLXCY=E=4SeU{ISgQ=a3g|8esq??4F#P6(o?u$paAszr|{Dr)?^>(8NH}qgT3km z;07#ywyj&~XGZ%G2=RcOqj<+k8xj(4o$c_39S3%7^s6KTZ#8Ek-6(nD@E#3ZNQ zWM{OEL1c|$pon&Cwx-%Y+Zu#E z4QS^mhE}ef>gZNXbX#%eC0$mJZd5Z+w`9b=_C=5IHyMU?;RH5*Ip7C3)PMZe>TMaM z9!YEGC{EG---OFu{{Id5+gDR41QY@rgut!+{{Zi3@Ev@Fi3$n Date: Fri, 4 May 2012 20:34:30 +0700 Subject: [PATCH 09/20] HAVING clause API code-coverage --- .../database/query_builder/group_test.php | 24 +++++++++++++++--- tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes tests/mocks/database/schema/skeleton.php | 12 ++++++--- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/tests/codeigniter/database/query_builder/group_test.php b/tests/codeigniter/database/query_builder/group_test.php index dd248ae9a1e..7d8abc33fba 100644 --- a/tests/codeigniter/database/query_builder/group_test.php +++ b/tests/codeigniter/database/query_builder/group_test.php @@ -22,16 +22,32 @@ public function set_up() */ public function test_group_by() { - $jobs = $this->db->select('job.name as job_name, job.id as job_id') + $jobs = $this->db->select('name') ->from('job') - ->group_by('job_name HAVING SUM(job_id) > 2') + ->group_by('name') + ->get() + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_having_by() + { + $jobs = $this->db->select('name') + ->from('job') + ->group_by('name') + ->having('SUM(id) > 2') ->get() ->result_array(); // Check the result $this->assertEquals(2, count($jobs)); - $this->assertEquals('Accountant', $jobs[0]['job_name']); - $this->assertEquals('Musician', $jobs[1]['job_name']); } } \ No newline at end of file diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index e4128b23f676b9a9d82582e390ad2d2a197fde32..d48e3317f8750d065af46921ac125cc39b977dfb 100755 GIT binary patch delta 332 zcmZpe!Pqc^ae}m<1p@cj4cd|EllFf!pxVL zuYurZMiwr{$t{e#S(yJYT$$K7XYzd}6Uj#F#(H*fQBlUG$dbgQoYd0d)FKdOnjFMj zAe@k#Uz%4^RGFYqmROXWkyxZ*GI=wzDk}qowh+)cdzcq#NGwuOSRBB?0RZ8wQeyxB delta 289 zcmZpe!Pqc^ae}m<5d#B*Fc32XF&_g1W8*{}V`(D>-A6LKO!f>cj4cd|EllFfmdw{6 zaI+u_7vtm>#@#GH4ZkKf&Y66l$%KhPV`8IT6D4;lLR+NJl+sQ3U6i 'VARCHAR', 'constraint' => 100, ), + 'country' => array( + 'type' => 'VARCHAR', + 'constraint' => 40, + ), )); static::$forge->add_key('id', TRUE); static::$forge->create_table('user', (strpos(static::$driver, 'pgsql') === FALSE)); @@ -96,10 +100,10 @@ public static function create_data() // Job Data $data = array( 'user' => array( - array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com'), - array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com'), - array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com'), - array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com'), + array('id' => 1, 'name' => 'Derek Jones', 'email' => 'derek@world.com', 'country' => 'US'), + array('id' => 2, 'name' => 'Ahmadinejad', 'email' => 'ahmadinejad@world.com', 'country' => 'Iran'), + array('id' => 3, 'name' => 'Richard A Causey', 'email' => 'richard@world.com', 'country' => 'US'), + array('id' => 4, 'name' => 'Chris Martin', 'email' => 'chris@world.com', 'country' => 'UK'), ), 'job' => array( array('id' => 1, 'name' => 'Developer', 'description' => 'Awesome job, but sometimes makes you bored'), From 44d8d881b401238661d81fc9db10482604b4cf43 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 20:43:45 +0700 Subject: [PATCH 10/20] DISTINCT clause API code-coverage --- .../database/query_builder/distinct_test.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/distinct_test.php diff --git a/tests/codeigniter/database/query_builder/distinct_test.php b/tests/codeigniter/database/query_builder/distinct_test.php new file mode 100644 index 00000000000..925eadb19ea --- /dev/null +++ b/tests/codeigniter/database/query_builder/distinct_test.php @@ -0,0 +1,34 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_distinct() + { + $users = $this->db->select('country') + ->distinct() + ->get('user') + ->result_array(); + + // Check the result + $this->assertEquals(3, count($users)); + } + +} \ No newline at end of file From 8ca31f34c855c783689198f0d352e6efec352b4d Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 4 May 2012 23:57:46 +0700 Subject: [PATCH 11/20] PDO SQLite bug fixed, for result_object --- system/database/drivers/pdo/pdo_result.php | 19 +++++++------------ tests/mocks/database/ci_test.sqlite | Bin 19456 -> 19456 bytes 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/system/database/drivers/pdo/pdo_result.php b/system/database/drivers/pdo/pdo_result.php index 19aee1dfc9c..0b8937cc5a0 100644 --- a/system/database/drivers/pdo/pdo_result.php +++ b/system/database/drivers/pdo/pdo_result.php @@ -84,19 +84,14 @@ public function result_assoc() // Define the output $output = array('assoc', 'object'); + // Initial value + $this->result_assoc = array() and $this->result_object = array(); + // Fetch the result - foreach ($output as $type) + while ($row = $this->_fetch_assoc()) { - // Define the method and handler - $res_method = '_fetch_'.$type; - $res_handler = 'result_'.$type; - - $this->$res_handler = array(); - - while ($row = $this->$res_method()) - { - $this->{$res_handler}[] = $row; - } + $this->result_assoc[] = $row; + $this->result_object[] = (object) $row; } // Save this as buffer and marked the fetch flag @@ -249,7 +244,7 @@ protected function _fetch_assoc() */ protected function _fetch_object() { - return $this->result_id->fetchObject(); + return $this->result_id->fetch(PDO::FETCH_OBJ); } } diff --git a/tests/mocks/database/ci_test.sqlite b/tests/mocks/database/ci_test.sqlite index d48e3317f8750d065af46921ac125cc39b977dfb..23a3de2a478cf280594e3bba7eac9577e4faa09f 100755 GIT binary patch delta 21 bcmZpe!Pqc^ae@?+GVeqgCm^{oVSzUQMIQz% delta 21 bcmZpe!Pqc^ae@?+ti?nbCm^{oVSzUQM`H$d From d2d329a99f60bebc36eebc1c7b3c1a94b9789b49 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:33:04 +0700 Subject: [PATCH 12/20] ORDER BY clause API code-coverage --- .../database/query_builder/order_test.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/order_test.php diff --git a/tests/codeigniter/database/query_builder/order_test.php b/tests/codeigniter/database/query_builder/order_test.php new file mode 100644 index 00000000000..01aa1c2b483 --- /dev/null +++ b/tests/codeigniter/database/query_builder/order_test.php @@ -0,0 +1,55 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_ascending() + { + $jobs = $this->db->order_by('name', 'asc') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Developer', $jobs[1]['name']); + $this->assertEquals('Musician', $jobs[2]['name']); + $this->assertEquals('Politician', $jobs[3]['name']); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_order_descending() + { + $jobs = $this->db->order_by('name', 'desc') + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(4, count($jobs)); + $this->assertEquals('Politician', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + $this->assertEquals('Developer', $jobs[2]['name']); + $this->assertEquals('Accountant', $jobs[3]['name']); + } +} \ No newline at end of file From be6fb4271ce723376930507dbe534f91344f26c7 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:35:41 +0700 Subject: [PATCH 13/20] LIMIT clause API code-coverage --- .../database/query_builder/limit_test.php | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/limit_test.php diff --git a/tests/codeigniter/database/query_builder/limit_test.php b/tests/codeigniter/database/query_builder/limit_test.php new file mode 100644 index 00000000000..704f3b651e8 --- /dev/null +++ b/tests/codeigniter/database/query_builder/limit_test.php @@ -0,0 +1,49 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit() + { + $jobs = $this->db->limit(2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_limit_and_offset() + { + $jobs = $this->db->limit(2, 2) + ->get('job') + ->result_array(); + + // Check the result + $this->assertEquals(2, count($jobs)); + $this->assertEquals('Accountant', $jobs[0]['name']); + $this->assertEquals('Musician', $jobs[1]['name']); + } +} \ No newline at end of file From c386b2a363c289afcfa07eea081050e35c1e86d8 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:42:02 +0700 Subject: [PATCH 14/20] count code-coverage --- .../database/query_builder/count_test.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/count_test.php diff --git a/tests/codeigniter/database/query_builder/count_test.php b/tests/codeigniter/database/query_builder/count_test.php new file mode 100644 index 00000000000..5e691692dbb --- /dev/null +++ b/tests/codeigniter/database/query_builder/count_test.php @@ -0,0 +1,44 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all() + { + $job_count = $this->db->count_all('job'); + + // Check the result + $this->assertEquals(4, $job_count); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_count_all_results() + { + $job_count = $this->db->like('name', 'ian') + ->count_all_results('job'); + + // Check the result + $this->assertEquals(2, $job_count); + } +} \ No newline at end of file From 9ec507badf60952750e76b5d83da54874dd19119 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 00:55:39 +0700 Subject: [PATCH 15/20] UPDATE and SET clause code-coverage --- .../database/query_builder/update_test.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/update_test.php diff --git a/tests/codeigniter/database/query_builder/update_test.php b/tests/codeigniter/database/query_builder/update_test.php new file mode 100644 index 00000000000..f5bbffd4f4c --- /dev/null +++ b/tests/codeigniter/database/query_builder/update_test.php @@ -0,0 +1,71 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the update + $job_data = array('name' => 'Programmer'); + + $this->db->where('id', 1) + ->update('job', $job_data); + + // Check updated record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Programmer', $job1->name); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_update_with_set() + { + // Check initial record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job1->name); + + // Do the update + $this->db->set('name', 'Vocalist'); + $this->db->update('job', NULL, 'id = 4'); + + // Check updated record + $job1 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Vocalist', $job1->name); + } +} \ No newline at end of file From 6657cc1672f3f466655b1e476028b9d46a16bd1c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:06:41 +0700 Subject: [PATCH 16/20] DELETE code-coverage --- .../database/query_builder/delete_test.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/delete_test.php diff --git a/tests/codeigniter/database/query_builder/delete_test.php b/tests/codeigniter/database/query_builder/delete_test.php new file mode 100644 index 00000000000..84ea7616ff5 --- /dev/null +++ b/tests/codeigniter/database/query_builder/delete_test.php @@ -0,0 +1,72 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete() + { + // Check initial record + $job1 = $this->db->where('id', 1) + ->get('job') + ->row(); + + $this->assertEquals('Developer', $job1->name); + + // Do the delete + $this->db->delete('job', array('id' => 1)); + + // Check the record + $job1 = $this->db->where('id', 1) + ->get('job'); + + $this->assertEmpty($job1->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_delete_several_tables() + { + // Check initial record + $user4 = $this->db->where('id', 4) + ->get('user') + ->row(); + + $job4 = $this->db->where('id', 4) + ->get('job') + ->row(); + + $this->assertEquals('Musician', $job4->name); + $this->assertEquals('Chris Martin', $user4->name); + + // Do the delete + $this->db->delete(array('job', 'user'), array('id' => 4)); + + // Check the record + $job4 = $this->db->where('id', 4)->get('job'); + $user4 = $this->db->where('id', 4)->get('user'); + + $this->assertEmpty($job4->result_array()); + $this->assertEmpty($user4->result_array()); + } + +} \ No newline at end of file From 85859b212e480e2e1a59aae50c759367d6794ecd Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:26:51 +0700 Subject: [PATCH 17/20] empty table API code-coverage --- .../database/query_builder/empty_test.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/empty_test.php diff --git a/tests/codeigniter/database/query_builder/empty_test.php b/tests/codeigniter/database/query_builder/empty_test.php new file mode 100644 index 00000000000..d1f56285f45 --- /dev/null +++ b/tests/codeigniter/database/query_builder/empty_test.php @@ -0,0 +1,39 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_empty_table() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->empty_table('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + +} \ No newline at end of file From 39f35fde6d023433e98904105f55f305483b6b5e Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:29:13 +0700 Subject: [PATCH 18/20] TRUNCATE code-coverage --- .../database/query_builder/truncate_test.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/codeigniter/database/query_builder/truncate_test.php diff --git a/tests/codeigniter/database/query_builder/truncate_test.php b/tests/codeigniter/database/query_builder/truncate_test.php new file mode 100644 index 00000000000..2a9c8a91ee8 --- /dev/null +++ b/tests/codeigniter/database/query_builder/truncate_test.php @@ -0,0 +1,61 @@ +db = Mock_Database_Schema_Skeleton::init(DB_DRIVER); + + Mock_Database_Schema_Skeleton::create_tables(); + Mock_Database_Schema_Skeleton::create_data(); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate() + { + // Check initial record + $jobs = $this->db->get('job')->result_array(); + + $this->assertEquals(4, count($jobs)); + + // Do the empty + $this->db->truncate('job'); + + // Check the record + $jobs = $this->db->get('job'); + + $this->assertEmpty($jobs->result_array()); + } + + // ------------------------------------------------------------------------ + + /** + * @see ./mocks/schema/skeleton.php + */ + public function test_truncate_with_from() + { + // Check initial record + $users = $this->db->get('user')->result_array(); + + $this->assertEquals(4, count($users)); + + // Do the empty + $this->db->from('user') + ->truncate(); + + // Check the record + $users = $this->db->get('user'); + + $this->assertEmpty($users->result_array()); + } + +} \ No newline at end of file From 51a7c0b98df29205d39bb404c2bcd12bfb4ed4cb Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:43:08 +0700 Subject: [PATCH 19/20] Clean up --- tests/README.md | 6 ------ tests/codeigniter/Setup_test.php | 10 +++++----- tests/travis/mysql.phpunit.xml | 6 +----- tests/travis/pdo/mysql.phpunit.xml | 4 ---- tests/travis/pdo/pgsql.phpunit.xml | 6 +----- tests/travis/pdo/sqlite.phpunit.xml | 6 +----- tests/travis/pgsql.phpunit.xml | 6 +----- tests/travis/sqlite.phpunit.xml | 6 +----- 8 files changed, 10 insertions(+), 40 deletions(-) diff --git a/tests/README.md b/tests/README.md index 6d83c34d8cf..b46f344cb92 100644 --- a/tests/README.md +++ b/tests/README.md @@ -2,12 +2,6 @@ Status : [![Build Status](https://secure.travis-ci.org/EllisLab/CodeIgniter.png?branch=feature/unit-tests)](http://travis-ci.org/EllisLab/CodeIgniter) -*Do not merge to default until these issues have been addressed* - -- Clean up naming conventions -- Figure out config stuff -- Figure out database testing - ### Introduction: This is the preliminary CodeIgniter testing documentation. It diff --git a/tests/codeigniter/Setup_test.php b/tests/codeigniter/Setup_test.php index 550245f2f24..b48e32bfb2b 100644 --- a/tests/codeigniter/Setup_test.php +++ b/tests/codeigniter/Setup_test.php @@ -2,12 +2,12 @@ class Setup_test extends PHPUnit_Framework_TestCase { - function test_nonsense() + function test_bootstrap_constants() { - $this->markTestIncomplete('not implemented'); - // ensure that our bootstrapped test environment - // is a good representation of an isolated CI install - //die('here'); + $this->assertTrue(defined('PROJECT_BASE')); + $this->assertTrue(defined('BASEPATH')); + $this->assertTrue(defined('APPPATH')); + $this->assertTrue(defined('VIEWPATH')); } } \ No newline at end of file diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index e9556f758cc..c5fcf13352a 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index 69eece24f3f..f6fcc1c3913 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -14,10 +14,6 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries ../../codeigniter/database diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index e68c3e02840..6a23227db07 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -14,11 +14,7 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries - ../../codeigniter/database + ../../codeigniter diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index 1871f622172..b85b7308a1b 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -14,11 +14,7 @@ - ../../codeigniter/Setup_test.php - ../../codeigniter/core - ../../codeigniter/helpers - ../../codeigniter/libraries - ../../codeigniter/database + ../../codeigniter diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index ad8aeded22c..78b6046cff2 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 628370e93e1..46e3d5073fd 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -14,11 +14,7 @@ - ../codeigniter/Setup_test.php - ../codeigniter/core - ../codeigniter/helpers - ../codeigniter/libraries - ../codeigniter/database + ../codeigniter From 82196b945e291c65fdb66b35e3205f786ce8e921 Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Sat, 5 May 2012 01:52:47 +0700 Subject: [PATCH 20/20] Remove temporary branch from travis whitelist --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 971f62f38a5..97ea0422dbd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,5 +25,4 @@ script: phpunit --configuration tests/travis/$DB.phpunit.xml branches: only: - develop - - master - - db-tests \ No newline at end of file + - master \ No newline at end of file