Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

New Zend\Validator\Bitwise #4940

Merged
merged 15 commits into from
Oct 22, 2013
Merged

New Zend\Validator\Bitwise #4940

merged 15 commits into from
Oct 22, 2013

Conversation

corentin-larose
Copy link
Contributor

Usage:

<?php
use Zend\validator\Bitwise;

$execute    = 0x1;
$write      = 0x2;
$read       = 0x4;
$controlSum = 0x7; // 0x1 | 0x2 | 0x4 === 0x7

$validator = new Bitwise($controlSum, Bitwise::OP_AND, false);

// or
$validator = new Bitwise(array(
    'control'  => $controlSum,
    'operator' => Bitwise::OP_AND,
    'strict'   => false
));

// or
$validator = new Bitwise();
$validator->setControl($controlSum);
$validator->setOperator(Bitwise::OP_AND);
$validator->setStrict(false); // Default value, just for example

// Does my value has at least one allowed bit set ?
$validator = new Bitwise($controlSum, Bitwise::OP_AND, false);
$validator->isValid(0x1); // true
$validator->isValid(0x2); // true
$validator->isValid(0x4); // true
$validator->isValid(0x1 | 0x8); // true since strict option is set to false by default
$validator->isValid(0x8); // false

// Does my value has only allowed bits set ?
$validator = new Bitwise($controlSum, Bitwise::OP_AND, true);
$validator->isValid(0x1); // true
$validator->isValid(0x2); // true
$validator->isValid(0x4); // true
$validator->isValid(0x1 | 0x8); // false since strict option is set to true
$validator->isValid(0x8); // false

// Does my value has only not allowed bit sets ?
$validator = new Bitwise($controlSum, Bitwise::OP_XOR);
$validator->isValid(0x1); // false
$validator->isValid(0x2); // false
$validator->isValid(0x4); // false
$validator->isValid(0x1 | 0x8); // false
$validator->isValid(0x8); // true

* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Validator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove @Package

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it ( @Package ) need to be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed this spot the first time !

public function __construct($options = null)
{
if ($options instanceof Traversable) {
$options = ArrayUtils::iteratorToArray($options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do not have nested options (i.e., if the options are only one level deep), just use iterator_to_array here.

@weierophinney
Copy link
Member

@corentin-larose Looks good - incorporate or answer the various feedback, and I'll review to merge.

@corentin-larose
Copy link
Contributor Author

Ok, I will take your changes and commit again.

@corentin-larose
Copy link
Contributor Author

@weierophinney should be ok/compliant if you want to merge.

@Maks3w
Copy link
Member

Maks3w commented Oct 21, 2013

@corentin-larose Your test are failing in Travis-CI

[concat] There were 12 errors:
[concat]
[concat] 1) ZendTest\Validator\BitwiseTest::testConstruct with data set #0 (array(), array(0, NULL, false))
[concat] Failed asserting that null is identical to 0.
[concat]
[concat] /home/travis/build/zendframework/zf2/tests/ZendTest/Validator/BitwiseTest.php:32
[concat]
[concat] 2) ZendTest\Validator\BitwiseTest::testConstruct with data set #1 (array(1), array(1, NULL, false))
[concat] Failed asserting that null is identical to 1.
[concat]
[concat] /home/travis/build/zendframework/zf2/tests/ZendTest/Validator/BitwiseTest.php:32
[concat]
[concat] 3) ZendTest\Validator\BitwiseTest::testConstruct with data set #2 (array(1, 'and'), array(1, 'and', false))
[concat] Failed asserting that null is identical to 1.
[concat]
[concat] /home/travis/build/zendframework/zf2/tests/ZendTest/Validator/BitwiseTest.php:32
[concat]
[concat] 4) ZendTest\Validator\BitwiseTest::testConstruct with data set #3 (array(1, 'and', true), array(1, 'and', true))
[concat] Failed asserting that null is identical to 1.
[concat]
[concat] /home/travis/build/zendframework/zf2/tests/ZendTest/Validator/BitwiseTest.php:32
[concat]
[concat] 5) ZendTest\Validator\BitwiseTest::testConstruct with data set #4 (array(1), array(1, NULL, false))
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::isvalid".
[concat]
[concat]
[concat] 6) ZendTest\Validator\BitwiseTest::testConstruct with data set #5 (array(1, 'and'), array(1, 'and', false))
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::isvalid".
[concat]
[concat]
[concat] 7) ZendTest\Validator\BitwiseTest::testConstruct with data set #6 (array(1, 'and', true), array(1, 'and', true))
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::isvalid".
[concat]
[concat]
[concat] 8) ZendTest\Validator\BitwiseTest::testBitwiseAndNotStrict
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::isvalid".
[concat]
[concat]
[concat] 9) ZendTest\Validator\BitwiseTest::testBitwiseAndStrict
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::isvalid".
[concat]
[concat]
[concat] 10) ZendTest\Validator\BitwiseTest::testBitwiseXor
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::isvalid".
[concat]
[concat]
[concat] 11) ZendTest\Validator\BitwiseTest::testSetOperator
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::setOperator".
[concat]
[concat]
[concat] 12) ZendTest\Validator\BitwiseTest::testSetStrict
[concat] PHP_CodeCoverage_Exception: Trying to @cover not existing method "Bitwise::setStrict".

@corentin-larose
Copy link
Contributor Author

@Maks3w, my bad, fixed the constructor to work the same way than other validators, forgot to push the U.T

@Maks3w
Copy link
Member

Maks3w commented Oct 21, 2013

@corentin-larose Tests run still failing.

@corentin-larose
Copy link
Contributor Author

Tests are ok, seems that Travis didn't run the most recent code (possible ?) I'm running tests on my last commit: 9339412.

corentin@QAPA-I:/media/localhost/zf2-fork/tests$ phpunit ZendTest/Validator/BitwiseTest.php
PHPUnit 3.7.24 by Sebastian Bergmann.

Configuration read from /media/localhost/zf2-fork/tests/phpunit.xml

.........

Time: 0 seconds, Memory: 3.00Mb

OK (9 tests, 48 assertions)

@Maks3w
Copy link
Member

Maks3w commented Oct 22, 2013

@corentin-larose Please read the log and make the necessary to changes for to have a clean Travis-CI run. If you see the log Travis use even a most recent version than you.

Try using full namespace class name instead the just Bitwise in that anotations.

@corentin-larose
Copy link
Contributor Author

@Maks3w doc block fixed, travis still fails, but on the usual think which is not related with Bitwise validator.

weierophinney added a commit that referenced this pull request Oct 22, 2013
weierophinney added a commit that referenced this pull request Oct 22, 2013
@weierophinney weierophinney merged commit eda0dac into zendframework:develop Oct 22, 2013
@ghost ghost assigned weierophinney Oct 22, 2013
@corentin-larose corentin-larose deleted the zend-validator-bitwise branch March 14, 2014 12:39
weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
…lidator-bitwise

New Zend\Validator\Bitwise
weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants