-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Nicolas Oelgart
committed
Nov 28, 2019
1 parent
bb0ee07
commit 03243e1
Showing
3 changed files
with
116 additions
and
19 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
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 |
---|---|---|
|
@@ -5,6 +5,8 @@ | |
* @link https://github.com/nicoSWD | ||
* @author Nicolas Oelgart <[email protected]> | ||
*/ | ||
|
||
use nicoSWD\Rule\Rule; | ||
use nicoSWD\Rule\tests\integration\AbstractTestBase; | ||
|
||
final class ObjectTest extends AbstractTestBase | ||
|
@@ -15,14 +17,86 @@ public function testObjects() | |
function test() { | ||
return 'test one two'; | ||
} | ||
|
||
function test2() { | ||
return new class () | ||
{ | ||
function miau() { | ||
return 'miau'; | ||
} | ||
}; | ||
} | ||
}; | ||
|
||
$variables = [ | ||
'my_obj' => $myObj, | ||
'my_string' => 'some test' | ||
]; | ||
|
||
$this->assertTrue($this->evaluate('my_obj.test() === "test one two"', $variables)); | ||
$this->assertFalse($this->evaluate('my_obj.test() === "oh no"', $variables)); | ||
$this->assertTrue($this->evaluate('my_obj.test2().miau() === "miau"', $variables)); | ||
} | ||
|
||
public function testPublicPropertyShouldBeAccessible() | ||
{ | ||
$myObj = new class { | ||
public $test = 'my string'; | ||
}; | ||
|
||
$variables = [ | ||
'my_obj' => $myObj, | ||
]; | ||
|
||
$this->assertTrue($this->evaluate('my_obj.test() === "my string"', $variables)); | ||
} | ||
|
||
public function testPublicMethodsShouldBeAccessibleMagicallyViaGet() | ||
{ | ||
$myObj = new class { | ||
public function getString() | ||
{ | ||
return 'some string'; | ||
} | ||
}; | ||
|
||
$variables = [ | ||
'my_obj' => $myObj, | ||
]; | ||
|
||
$this->assertTrue($this->evaluate('my_obj.string() === "some string"', $variables)); | ||
} | ||
|
||
public function testPublicMethodsShouldBeAccessibleMagicallyViaIs() | ||
{ | ||
$myObj = new class { | ||
public function isString($string) | ||
{ | ||
return $string; | ||
} | ||
|
||
public function yes() | ||
{ | ||
return 'yes'; | ||
} | ||
}; | ||
|
||
$variables = [ | ||
'my_obj' => $myObj, | ||
]; | ||
|
||
$this->assertTrue($this->evaluate('my_obj.string(my_obj.yes()) === "yes"', $variables)); | ||
} | ||
|
||
public function testUndefinedMethodsShouldThrowAnError() | ||
{ | ||
$myObj = new class {}; | ||
|
||
$variables = [ | ||
'my_obj' => $myObj, | ||
]; | ||
|
||
$rule = new Rule('my_obj.nope() === false', $variables); | ||
|
||
$this->assertFalse($rule->isValid()); | ||
$this->assertSame('Undefined method "nope" at position 0', $rule->getError()); | ||
} | ||
} |