-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using a single 'name' instead of 'first/last' -- with tests
* Moved names over to just 'name' and removed 'first_name/last_name' from schema * closes #45 * Added Person unit tests * Configured Travis Continuous Integration * TODO: Add more tests
- Loading branch information
David Kobia
committed
Oct 1, 2013
1 parent
5618873
commit 6dfc723
Showing
12 changed files
with
239 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
language: php | ||
|
||
php: | ||
- 5.3 | ||
|
||
before_install: | ||
- "git submodule update --init --recursive" | ||
|
||
services: | ||
- mysql | ||
before_script: | ||
- "pear channel-discover pear.phing.info" | ||
- "pear install phing/phing" | ||
- "phpenv rehash" | ||
- "composer install" | ||
|
||
script: "phing test" | ||
- composer install --no-interaction --prefer-source # Have to prefer source or hit github rate limit | ||
- git submodule update --init --recursive | ||
- mkdir application/cache application/logs | ||
- chmod 777 application/cache application/logs | ||
# db setup | ||
- mysql -e 'create database pingapp_test;' | ||
- ./minion --task=migrations:run --up | ||
# webserver setup | ||
- php -S localhost:8000 httpdocs/index.php & | ||
- sleep 3 | ||
|
||
notifications: | ||
irc: | ||
channels: | ||
- "irc.freenode.org#kohana" | ||
template: | ||
- "%{repository}/%{branch} (%{commit}) - %{author}: %{message}" | ||
- "Build details: %{build_url}" | ||
email: false | ||
script: | ||
- /vendor/bin/phpunit -c application/tests/phpunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php defined('SYSPATH') OR die('No direct script access.'); | ||
|
||
class Migration_1_20131001090904 extends Minion_Migration_Base { | ||
|
||
/** | ||
* Run queries needed to apply this migration | ||
* | ||
* @param Kohana_Database $db Database connection | ||
*/ | ||
public function up(Kohana_Database $db) | ||
{ | ||
// Add a new 'name' column | ||
$db->query(NULL, "ALTER TABLE `people` ADD `name` VARCHAR(150) NULL DEFAULT NULL AFTER `user_id`;"); | ||
|
||
// Migrate names to new column | ||
$this->_migrate_old(); | ||
|
||
// Drop old columns | ||
$db->query(NULL, "ALTER TABLE `people` DROP `first_name`;"); | ||
$db->query(NULL, "ALTER TABLE `people` DROP `last_name`;"); | ||
} | ||
|
||
/** | ||
* Run queries needed to remove this migration | ||
* | ||
* @param Kohana_Database $db Database connection | ||
*/ | ||
public function down(Kohana_Database $db) | ||
{ | ||
// Restore first_name and last_name | ||
$db->query(NULL, "ALTER TABLE `people` ADD `first_name` VARCHAR(100) NULL DEFAULT NULL AFTER `user_id`;"); | ||
$db->query(NULL, "ALTER TABLE `people` ADD `last_name` VARCHAR(100) NULL DEFAULT NULL AFTER `first_name`;"); | ||
|
||
// Migrate names back to old columns | ||
$this->_un_migrate_old(); | ||
|
||
// Drop name column | ||
$db->query(NULL, "ALTER TABLE `people` DROP `name`;"); | ||
} | ||
|
||
|
||
/** | ||
* Migrate Old People | ||
* @return void | ||
*/ | ||
private function _migrate_old() | ||
{ | ||
$people = ORM::factory('Person') | ||
->find_all(); | ||
|
||
foreach ($people as $person) | ||
{ | ||
$person->name = $person->first_name.' '.$person->last_name; | ||
$person->save(); | ||
} | ||
} | ||
|
||
/** | ||
* UnMigrate Old People | ||
* @return void | ||
*/ | ||
private function _un_migrate_old() | ||
{ | ||
$people = ORM::factory('Person') | ||
->find_all(); | ||
|
||
foreach ($people as $person) | ||
{ | ||
$name = explode(' ', $person->name); | ||
$person->first_name = $name[0]; | ||
$person->last_name = (isset($name[1])) ? $name[1] : ''; | ||
$person->save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php defined('SYSPATH') or die('No direct script access allowed.'); | ||
|
||
/** | ||
* Unit tests for the person model | ||
* | ||
* @author Ushahidi Team <[email protected]> | ||
* @package Ushahidi\Application\Tests | ||
* @copyright Ushahidi - http://www.ushahidi.com | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License Version 3 (GPLv3) | ||
*/ | ||
|
||
class PersonModelTest extends Unittest_TestCase { | ||
/** | ||
* Provider for test_validate_valid | ||
* | ||
* @access public | ||
* @return array | ||
*/ | ||
public function provider_validate_valid() | ||
{ | ||
return array( | ||
array( | ||
// Valid person data | ||
array( | ||
'name' => 'Joe Schmoe', | ||
'status' => 'ok', | ||
) | ||
), | ||
array( | ||
// Valid person data | ||
array( | ||
'name' => 'Bill Murray', | ||
'status' => 'notok', | ||
) | ||
), | ||
array( | ||
// Valid person data | ||
array( | ||
'name' => 'Miley Cyrus', | ||
'status' => 'unknown', | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Provider for test_validate_invalid | ||
* | ||
* @access public | ||
* @return array | ||
*/ | ||
public function provider_validate_invalid() | ||
{ | ||
return array( | ||
array( | ||
// Invalid person data set 1 - No Data | ||
array() | ||
), | ||
array( | ||
// Invalid person data set 2 - Missing Name | ||
array( | ||
'status' => 'ok', | ||
) | ||
), | ||
array( | ||
// Invalid person data set 4 - Invalid status | ||
array( | ||
'name' => 'Batcave Chris', | ||
'status' => 'not okay', | ||
) | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Test Validate Valid Entries | ||
* | ||
* @dataProvider provider_validate_valid | ||
* @return void | ||
*/ | ||
public function test_validate_valid($set) | ||
{ | ||
$person = ORM::factory('Person'); | ||
$person->values($set); | ||
|
||
try | ||
{ | ||
$person->check(); | ||
} | ||
catch (ORM_Validation_Exception $e) | ||
{ | ||
$this->fail('This entry qualifies as invalid when it should be valid: '. json_encode($e->errors('models'))); | ||
} | ||
} | ||
|
||
/** | ||
* Test Validate Invalid Entries | ||
* | ||
* @dataProvider provider_validate_invalid | ||
* @return void | ||
*/ | ||
public function test_validate_invalid($set) | ||
{ | ||
$person = ORM::factory('Person'); | ||
$person->values($set); | ||
|
||
try | ||
{ | ||
$person->check(); | ||
} | ||
catch (ORM_Validation_Exception $e) | ||
{ | ||
return; | ||
} | ||
|
||
$this->fail('This entry qualifies as valid when it should be invalid'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<phpunit colors="true" bootstrap="../../modules/unittest/bootstrap.php"> | ||
<testsuites> | ||
<testsuite name="PingApp Tests"> | ||
<directory>./</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
{ | ||
"require": { | ||
"phpunit/phpunit": "3.7.24", | ||
"phpunit/phpunit": "3.7.*", | ||
"phpunit/dbunit": ">=1.2", | ||
"phing/phing": "dev-master", | ||
|
||
"twilio/sdk": "dev-master" | ||
} | ||
} | ||
}, | ||
"config": { | ||
"bin-dir": "bin/" | ||
} | ||
} |