Skip to content

Commit

Permalink
FIX: missing Model::__unset($property)
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-Julian Pogner authored and treffynnon committed Dec 14, 2016
1 parent e7fe09e commit 76f0419
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Changelog
* Global setting to allow static requests to avoid being forced in to using the namespace + class as the auto table name [[michaelward82](https://github.com/michaelward82)] - [issue #100](https://github.com/j4mie/paris/issues/100)
* Document conflict between static Model calling and auto_prefix_models [[michaelward82](https://github.com/michaelward82)] - [issue #102](https://github.com/j4mie/paris/issues/102)
* Added @method tags for magic methods [[stellis](https://github.com/stellis)] - [issue #104](https://github.com/j4mie/paris/issues/104)
* Add missing `__unset()` magic method [[qyanu](https://github.com/qyanu)] - [issue #106](https://github.com/j4mie/paris/issues/106)

#### 1.5.4 - released 2014-09-23

Expand Down
10 changes: 10 additions & 0 deletions paris.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,16 @@ public function __set($property, $value) {
$this->orm->set($property, $value);
}

/**
* Magic unset method, allows unset($model->property)
*
* @param string $property
* @return void
*/
public function __unset($property) {
$this->orm->__unset($property);
}

/**
* Magic isset method, allows isset($model->property) to work correctly.
*
Expand Down
29 changes: 29 additions & 0 deletions test/MagicMethodsTest.php
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");
}
}

0 comments on commit 76f0419

Please sign in to comment.