-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #125 from j4mie/develop
Release 1.5.5
- Loading branch information
Showing
10 changed files
with
298 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
*.swp | ||
*.sqlite | ||
docs/_build | ||
nbproject/ | ||
nbproject/ | ||
/vendor | ||
/composer.lock |
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,6 +1,7 @@ | ||
language: php | ||
php: | ||
- 5.2 | ||
- 5.3 | ||
- 5.4 | ||
- 5.6 | ||
- 7.0 | ||
script: "phpunit --colors --coverage-text" |
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
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,89 @@ | ||
<?php | ||
namespace | ||
{ | ||
class HasManyThroughTest extends PHPUnit_Framework_TestCase | ||
{ | ||
private $sql = ' | ||
CREATE TABLE post ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
title TEXT | ||
); | ||
CREATE TABLE tag ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT | ||
); | ||
CREATE TABLE post_tag ( | ||
post_id INTEGER, | ||
tag_id INTEGER, | ||
FOREIGN KEY(post_id) REFERENCES post(id), | ||
FOREIGN KEY(tag_id) REFERENCES tag(id) | ||
); | ||
INSERT INTO post (title) | ||
VALUES ("A Blog Post Title: PHPUnit Testing"); | ||
INSERT INTO tag (name) VALUES ("php"); | ||
INSERT INTO tag (name) VALUES ("programming"); | ||
INSERT INTO tag (name) VALUES ("github"); | ||
INSERT INTO post_tag (post_id, tag_id) VALUES (1, 1); | ||
INSERT INTO post_tag (post_id, tag_id) VALUES (1, 2); | ||
INSERT INTO post_tag (post_id, tag_id) VALUES (1, 3); | ||
'; | ||
|
||
public function setUp () { | ||
$db_handle = new PDO('sqlite::memory:'); | ||
$db_handle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING); | ||
$db_handle->exec($this->sql); | ||
|
||
ORM::set_db($db_handle); | ||
ORM::configure('logging', true); | ||
} | ||
|
||
public function tearDown () | ||
{ | ||
ORM::configure('logging', false); | ||
ORM::set_db(null); | ||
} | ||
|
||
public function testHasManyThrough () { | ||
$video = \PHPProject\Models\Post::find_one(1); | ||
$tags = $video->tags()->find_many(); | ||
$this->assertArrayHasKey('id', $tags[0]->as_array()); | ||
$this->assertArrayHasKey('name', $tags[0]->as_array()); | ||
} | ||
} | ||
} | ||
|
||
// We need to use the namespaces here to test whether | ||
// the table names are being correctly generated when | ||
// using $_table_use_short_name = true; | ||
namespace PHPProject\Models | ||
{ | ||
class Post extends \Model | ||
{ | ||
public static $_table_use_short_name = true; | ||
|
||
public function tags () | ||
{ | ||
return $this->has_many_through('\\PHPProject\\Models\\Tag'); | ||
} | ||
} | ||
class Tag extends \Model | ||
{ | ||
public static $_table_use_short_name = true; | ||
|
||
public function posts () | ||
{ | ||
return $this->has_many_through('\\PHPProject\\Models\\Post'); | ||
} | ||
} | ||
class PostTag extends \Model | ||
{ | ||
public static $_table_use_short_name = true; | ||
} | ||
} | ||
?> |
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,29 @@ | ||
<?php | ||
|
||
class MagicMethodsTest extends PHPUnit_Framework_TestCase { | ||
|
||
public function setUp() { | ||
// Set up the dummy database connection | ||
ORM::set_db(new MockPDO('sqlite::memory:')); | ||
|
||
// Enable logging | ||
ORM::configure('logging', true); | ||
|
||
Model::$auto_prefix_models = null; | ||
} | ||
|
||
public function tearDown() { | ||
ORM::configure('logging', false); | ||
ORM::set_db(null); | ||
|
||
Model::$auto_prefix_models = null; | ||
} | ||
|
||
public function testMagicMethodUnset() { | ||
$model = Model::factory("Simple")->create(); | ||
$model->property = "test"; | ||
unset($model->property); | ||
$this->assertFalse(isset($model->property)); | ||
$this->assertTrue($model->get("property")!="test"); | ||
} | ||
} |
Oops, something went wrong.