From 9f72aa0225c5907405179eec7ec9a30baafe5259 Mon Sep 17 00:00:00 2001 From: Adrien Gallou Date: Fri, 25 Dec 2015 23:58:37 +0100 Subject: [PATCH] add a contain operator This operator is will improve the readability of the tags filter. Before, we needed to write something like this : ``` ./vendor/bin/atoum -d tests --filter 'not ("needsDatabase" in tags)' ``` Now, we could write something like this : ``` ./vendor/bin/atoum -d tests --filter 'not (tags contains "needsDatabase")' ``` --- CHANGELOG.md | 4 ++++ README.md | 7 +++++++ classes/ruler.php | 1 + tests/units/classes/ruler.php | 3 +++ 4 files changed, 15 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec46e33..5c3f6a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# `dev-master` + +* [#24](https://github.com/atoum/ruler-extension/pull/24) Add a contain operator ([@agallou]) + # 1.0.3 - 2015-06-24 * [#17](https://github.com/atoum/ruler-extension/pull/17) Move to Hoa\Ustring ([@Metalaka](https://github.com/Metalaka)) diff --git a/README.md b/README.md index 1e90c94..2670f46 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,17 @@ Those variables are available in the filter: Run all tests except those who have the `needsDatabase` tag: +``` +./vendor/bin/atoum -d tests --filter 'not (tags contains "needsDatabase")' +``` + +You can also use the ruler's default `in` operator, but in that case that's less readable: + ``` ./vendor/bin/atoum -d tests --filter 'not ("needsDatabase" in tags)' ``` + Run all tests with a method named `testMethod1`: ``` diff --git a/classes/ruler.php b/classes/ruler.php index 4c3a837..82bb5fe 100644 --- a/classes/ruler.php +++ b/classes/ruler.php @@ -25,6 +25,7 @@ public function __construct($rule) { $this->rule = HoaRuler::interpret($rule); $this->ruler = new HoaRuler(); + $this->ruler->getAsserter()->setOperator('contains', function (Array $a, $b) { return in_array($b, $a); }); } /** diff --git a/tests/units/classes/ruler.php b/tests/units/classes/ruler.php index e632f79..476ef1b 100644 --- a/tests/units/classes/ruler.php +++ b/tests/units/classes/ruler.php @@ -55,6 +55,9 @@ protected function testFilterDataProvider() 'not("unSuperTagAuNiveauDeLaMethode1" in tags)' => array( 'testMethod1' => true, ), + 'not(tags contains "unSuperTagAuNiveauDeLaMethode1")' => array( + 'testMethod1' => true, + ), 'method = "testMethod1"' => array( 'testMethod1' => false, ),