├── logo.jpg ├── .gitignore ├── .provision ├── files │ └── dot │ │ ├── .vimrc │ │ ├── .bashrc │ │ ├── .bash_aliases │ │ └── .bash_git ├── exec │ ├── 02.composer.sh │ └── 01.packages.sh ├── init.sh └── system │ ├── dot-files.sh │ └── execute-files.sh ├── .gitattributes ├── src └── exceptions │ ├── ArgumentException.php │ ├── InvalidEmptyException.php │ ├── InvalidNotBoolException.php │ ├── InvalidNotIntException.php │ ├── InvalidNotNullException.php │ ├── InvalidNotArrayException.php │ ├── InvalidNotEmptyException.php │ ├── InvalidNotFloatException.php │ ├── InvalidNotObjectException.php │ ├── InvalidNotStringException.php │ ├── InvalidNotResourceException.php │ ├── InvalidNotIntAndNotFloatException.php │ ├── InvalidNotNullAndNotIntException.php │ ├── InvalidNotIntAndNotStringException.php │ ├── InvalidNotNullAndNotStringException.php │ ├── InvalidNotIntAndNotFloatAndNotStringException.php │ ├── InvalidDigitException.php │ ├── InvalidNullException.php │ ├── InvalidRegExpPatternException.php │ ├── ArrayKeyNotExistsException.php │ ├── InvalidNotSameValueException.php │ ├── InvalidIntException.php │ ├── InvalidBoolException.php │ ├── NumberNotPositiveException.php │ ├── InvalidArrayException.php │ ├── InvalidFloatException.php │ ├── InvalidStringException.php │ ├── InvalidResourceException.php │ ├── NumberNotNegativeException.php │ ├── ValueNotInArrayException.php │ ├── InvalidNumericException.php │ ├── InvalidIntOrFloatException.php │ ├── InvalidNullOrIntException.php │ ├── InvalidIntOrStringException.php │ ├── InvalidNullOrStringException.php │ ├── StringNotMatchGlobException.php │ ├── StringNotMatchRegExpException.php │ ├── InvalidIntOrFloatOrStringException.php │ ├── InvalidStringLengthException.php │ ├── LengthNotLessException.php │ ├── LengthNotGreaterException.php │ ├── InvalidSameValueException.php │ ├── NumberNotLessException.php │ ├── NumberNotGreaterException.php │ ├── NumberNotLessStrictlyException.php │ ├── NumberNotGreaterStrictlyException.php │ ├── LengthNotBetweenException.php │ ├── InvalidArrayCountException.php │ ├── NumberNotBetweenException.php │ └── NumberNotBetweenStrictlyException.php ├── .travis.yml ├── Vagrantfile ├── composer.json ├── phpunit.xml.dist ├── LICENSE ├── tests ├── unit │ └── exceptions │ │ ├── InvalidEmptyExceptionTest.php │ │ ├── InvalidNotIntExceptionTest.php │ │ ├── InvalidNotBoolExceptionTest.php │ │ ├── InvalidNotNullExceptionTest.php │ │ ├── InvalidNotArrayExceptionTest.php │ │ ├── InvalidNotEmptyExceptionTest.php │ │ ├── InvalidNotFloatExceptionTest.php │ │ ├── InvalidNotStringExceptionTest.php │ │ ├── InvalidNotObjectExceptionTest.php │ │ ├── InvalidNotResourceExceptionTest.php │ │ ├── InvalidNotNullAndNotIntExceptionTest.php │ │ ├── InvalidNotIntAndNotFloatExceptionTest.php │ │ ├── InvalidNotIntAndNotStringExceptionTest.php │ │ ├── InvalidNotNullAndNotStringExceptionTest.php │ │ ├── InvalidNotIntAndNotFloatAndNotStringExceptionTest.php │ │ ├── InvalidNotSameValueExceptionTest.php │ │ ├── InvalidDigitExceptionTest.php │ │ ├── ArrayKeyNotExistsExceptionTest.php │ │ ├── InvalidNullExceptionTest.php │ │ ├── InvalidRegExpPatternExceptionTest.php │ │ ├── ValueNotInArrayExceptionTest.php │ │ ├── InvalidStringExceptionTest.php │ │ ├── InvalidIntExceptionTest.php │ │ ├── InvalidBoolExceptionTest.php │ │ ├── InvalidArrayExceptionTest.php │ │ ├── InvalidFloatExceptionTest.php │ │ ├── InvalidResourceExceptionTest.php │ │ ├── NumberNotNegativeExceptionTest.php │ │ ├── NumberNotPositiveExceptionTest.php │ │ ├── InvalidNumericExceptionTest.php │ │ ├── InvalidSameValueExceptionTest.php │ │ ├── InvalidNullOrIntExceptionTest.php │ │ ├── InvalidIntOrFloatExceptionTest.php │ │ ├── InvalidIntOrStringExceptionTest.php │ │ ├── InvalidNullOrStringExceptionTest.php │ │ ├── InvalidIntOrFloatOrStringExceptionTest.php │ │ ├── LengthNotLessExceptionTest.php │ │ ├── LengthNotGreaterExceptionTest.php │ │ ├── InvalidStringLengthExceptionTest.php │ │ ├── StringNotMatchGlobExceptionTest.php │ │ ├── StringNotMatchRegExpExceptionTest.php │ │ ├── NumberNotLessExceptionTest.php │ │ ├── NumberNotGreaterExceptionTest.php │ │ ├── NumberNotLessStrictlyExceptionTest.php │ │ ├── NumberNotGreaterStrictlyExceptionTest.php │ │ ├── InvalidArrayCountExceptionTest.php │ │ ├── LengthNotBetweenExceptionTest.php │ │ ├── NumberNotBetweenExceptionTest.php │ │ └── NumberNotBetweenStrictlyExceptionTest.php └── BaseUnitTestCase.php └── .scrutinizer.yml /logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ko-ko-ko/php-assert/HEAD/logo.jpg -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .vagrant/ 3 | composer.phar 4 | vendor/ 5 | coverage.txt 6 | 7 | !.gitignore -------------------------------------------------------------------------------- /.provision/files/dot/.vimrc: -------------------------------------------------------------------------------- 1 | set nocompatible 2 | filetype off 3 | set paste 4 | set tabstop=4 5 | set number 6 | 7 | -------------------------------------------------------------------------------- /.provision/exec/02.composer.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | COMPOSER_PATH="/usr/local/bin/composer" 4 | 5 | curl -s -L https://getcomposer.org/composer.phar > $COMPOSER_PATH 6 | chmod +x $COMPOSER_PATH 7 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Autodetect text files 2 | 3 | *.pp text eol=lf 4 | *.sh text eol=lf 5 | *.yaml text eol=lf 6 | .bash_aliases text eol=lf 7 | .vimrc text eol=lf 8 | .bash_git eol=lf 9 | .profile eol=lf 10 | -------------------------------------------------------------------------------- /.provision/files/dot/.bashrc: -------------------------------------------------------------------------------- 1 | # User specific aliases and functions 2 | 3 | if [ -f /etc/bashrc ]; then 4 | . /etc/bashrc 5 | fi 6 | 7 | source $HOME/.bash_aliases 8 | source $HOME/.bash_git 9 | 10 | export PATH 11 | -------------------------------------------------------------------------------- /.provision/exec/01.packages.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | apt-get update > /dev/null 2>&1 4 | 5 | apt-get install -y vim mc htop \ 6 | git mercurial \ 7 | curl \ 8 | php-pear php5-dev php5-cli php5-curl php5-xdebug > /dev/null 2>&1 9 | 10 | -------------------------------------------------------------------------------- /.provision/init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Init" 4 | 5 | if [[ ! -d '/.provision-stuff' ]]; then 6 | mkdir '/.provision-stuff' 7 | echo 'Created directory /.provision-stuff' 8 | fi 9 | 10 | bash /vagrant/.provision/system/execute-files.sh 11 | bash /vagrant/.provision/system/dot-files.sh 12 | 13 | clear 14 | -------------------------------------------------------------------------------- /.provision/system/dot-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | shopt -s dotglob 4 | 5 | for FILE in "/vagrant/.provision/files/dot/*.*" 6 | do 7 | FILE_NAME=$(basename "$FILE") 8 | 9 | cp -r $FILE /home/vagrant/ 10 | cp -r $FILE /root/ 11 | 12 | chown -R vagrant:vagrant /home/vagrant/$FILE_NAME 13 | chown -R root:root /root/$FILE_NAME 14 | done 15 | -------------------------------------------------------------------------------- /src/exceptions/ArgumentException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class ArgumentException extends \InvalidArgumentException 11 | { 12 | } -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.4 5 | - 5.5 6 | - 5.6 7 | - 7.0 8 | 9 | install: 10 | - composer self-update && composer --version 11 | - composer install 12 | 13 | script: 14 | - php vendor/bin/phpunit -c phpunit.xml.dist --coverage-clover=./coverage.txt 15 | - wget https://scrutinizer-ci.com/ocular.phar 16 | - php ocular.phar code-coverage:upload --format=php-clover ./coverage.txt 17 | 18 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | VAGRANTFILE_API_VERSION = "2" 2 | 3 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 4 | config.vm.box = "ubuntu/trusty64" 5 | 6 | config.vm.hostname = "php-assert" 7 | 8 | config.vm.network "private_network", ip: "192.168.100.127" 9 | 10 | config.vm.synced_folder "./", "/home/vagrant/work" 11 | 12 | config.vm.provider "virtualbox" do |vb| 13 | vb.customize ["modifyvm", :id, "--memory", "1024"] 14 | end 15 | 16 | config.vm.provision "shell", path: ".provision/init.sh" 17 | end 18 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ko-ko-ko/assert", 3 | "description": "Fast flexible php assert", 4 | "require-dev": { 5 | "phpunit/phpunit": "~4.8.21" 6 | }, 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "Roman Levishchenko", 11 | "email": "index.0h@gmail.com" 12 | } 13 | ], 14 | "autoload": { 15 | "psr-4": { 16 | "KoKoKo\\assert\\": "src", 17 | "KoKoKo\\assert\\tests\\": "tests" 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | 11 | tests/unit 12 | 13 | 14 | 15 | 16 | 17 | src 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/exceptions/InvalidEmptyException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidEmptyException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws \InvalidArgumentException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "empty"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotBoolException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotBoolException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not bool"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotIntException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotIntException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not int"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotNullException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotNullException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not null"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotArrayException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotArrayException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not array"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotEmptyException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotEmptyException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not empty"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotFloatException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotFloatException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not float"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotObjectException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotObjectException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not object"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not string"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotResourceException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotResourceException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not resource"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotIntAndNotFloatException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotIntAndNotFloatException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not int" and "not float"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNotNullAndNotIntException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotNullAndNotIntException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not null" and "not int"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/exceptions/InvalidNotIntAndNotStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotIntAndNotStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not int" and "not string"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/exceptions/InvalidNotNullAndNotStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotNullAndNotStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not null" and "not string"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/exceptions/InvalidNotIntAndNotFloatAndNotStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotIntAndNotFloatAndNotStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @throws InvalidStringException 15 | */ 16 | public function __construct($variableName) 17 | { 18 | if (!is_string($variableName)) { 19 | throw new InvalidStringException('variableName', $variableName); 20 | } 21 | 22 | parent::__construct( 23 | sprintf( 24 | 'Variable "$%s" must be "not int" and "not float" and "not string"', 25 | $variableName 26 | ) 27 | ); 28 | } 29 | } -------------------------------------------------------------------------------- /.provision/system/execute-files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo "Run scripts from /vagrant/.provision/exec/" 4 | 5 | SCRIPT_LOG="/.provision-stuff/execute-files.txt" 6 | TMP_ALL_PATH="/tmp/execute-files-all.txt" 7 | TMP_EXECUTED_PATH="/tmp/execute-files-executed.txt" 8 | FILES_PATH="/vagrant/.provision/exec/" 9 | SPLIT="------------------------------------------------------------------" 10 | 11 | if [[ ! -f $SCRIPT_LOG ]]; then 12 | touch $SCRIPT_LOG 13 | fi 14 | 15 | cat $SCRIPT_LOG > $TMP_EXECUTED_PATH 16 | 17 | find $FILES_PATH -maxdepth 1 -not -path $FILES_PATH'.*' -type f \( ! -iname ".gitignore" \) | sort > $TMP_ALL_PATH 18 | 19 | FILES_TO_RUN=( `comm -13 $SCRIPT_LOG $TMP_ALL_PATH` ) 20 | 21 | for file in "${FILES_TO_RUN[@]}" 22 | do 23 | chmod +x $file 24 | echo $SPLIT 25 | echo "Exec: $file" 26 | /bin/bash $file 27 | echo "Finish: $file" 28 | echo $file >> $TMP_EXECUTED_PATH 29 | done 30 | 31 | cat $TMP_EXECUTED_PATH | sort > $SCRIPT_LOG 32 | 33 | rm $TMP_ALL_PATH $TMP_EXECUTED_PATH 34 | 35 | echo $SPLIT 36 | 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Roman Levishchenko 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /src/exceptions/InvalidDigitException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidDigitException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @throws InvalidStringException 16 | */ 17 | public function __construct($variableName, $variableValue) 18 | { 19 | if (!is_string($variableName)) { 20 | throw new InvalidStringException('variableName', $variableName); 21 | } elseif (!is_string($variableValue)) { 22 | throw new InvalidStringException('variableValue', $variableValue); 23 | } 24 | 25 | parent::__construct( 26 | sprintf( 27 | 'Variable "$%s" must be "digit", actual value: "%s"', 28 | $variableName, 29 | $variableValue 30 | ) 31 | ); 32 | } 33 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNullException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNullException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int $variableValue 15 | * @throws InvalidNotNullException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_null($variableValue)) { 23 | throw new InvalidNotNullException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "null", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidRegExpPatternException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidRegExpPatternException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @throws InvalidStringException 16 | */ 17 | public function __construct($variableName, $variableValue) 18 | { 19 | if (!is_string($variableName)) { 20 | throw new InvalidStringException('variableName', $variableName); 21 | } elseif (!is_string($variableValue)) { 22 | throw new InvalidStringException('variableValue', $variableValue); 23 | } 24 | 25 | parent::__construct( 26 | sprintf( 27 | 'Variable "$%s" must be "correct RegExp pattern", actual value: "%s"', 28 | $variableName, 29 | $variableValue 30 | ) 31 | ); 32 | } 33 | } -------------------------------------------------------------------------------- /src/exceptions/ArrayKeyNotExistsException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class ArrayKeyNotExistsException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $key 15 | * @throws InvalidIntOrStringException 16 | * @throws InvalidNotEmptyException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $key) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_int($key) && !is_string($key)) { 24 | throw new InvalidIntOrStringException('key', $key); 25 | } 26 | 27 | parent::__construct( 28 | sprintf( 29 | 'Variable "$%s" must contain key: "%s"', 30 | $variableName, 31 | $key 32 | ) 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/exceptions/InvalidNotSameValueException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNotSameValueException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float|bool|resource|array $variableValue 15 | * @throws InvalidNotEmptyException 16 | * @throws InvalidNotIntException 17 | * @throws InvalidNotStringException 18 | * @throws InvalidStringException 19 | */ 20 | public function __construct($variableName, $variableValue) 21 | { 22 | if (!is_string($variableName)) { 23 | throw new InvalidStringException('variableName', $variableName); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be not same as: "%s"', 29 | $variableName, 30 | print_r($variableValue, true) 31 | ) 32 | ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/exceptions/InvalidIntException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidIntException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|bool|float|null|resource|string $variableValue 15 | * @throws InvalidNotIntException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_int($variableValue)) { 23 | throw new InvalidNotIntException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "int", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidBoolException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidBoolException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|float|int|null|resource|string $variableValue 15 | * @throws InvalidNotBoolException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_bool($variableValue)) { 23 | throw new InvalidNotBoolException($variableName); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "bool", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/NumberNotPositiveException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotPositiveException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int $variableValue 15 | * @throws InvalidIntOrFloatException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 23 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "positive", actual value: "%s"', 29 | $variableName, 30 | $variableValue 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidArrayException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidArrayException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param bool|float|int|null|resource|string $variableValue 15 | * @throws InvalidNotArrayException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_array($variableValue)) { 23 | throw new InvalidNotArrayException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "array", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidFloatException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidFloatException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|bool|int|null|resource|string $variableValue 15 | * @throws InvalidNotFloatException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_float($variableValue)) { 23 | throw new InvalidNotFloatException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "float", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|bool|float|int|null|resource $variableValue 15 | * @throws InvalidNotStringException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_string($variableValue)) { 23 | throw new InvalidNotStringException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "string", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidResourceException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidResourceException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|bool|float|int|null|string $variableValue 15 | * @throws InvalidNotResourceException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_resource($variableValue)) { 23 | throw new InvalidNotResourceException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "resource", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/NumberNotNegativeException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotNegativeException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @throws InvalidIntOrFloatException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 23 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "negative", actual value: "%s"', 29 | $variableName, 30 | (string) $variableValue 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/ValueNotInArrayException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class ValueNotInArrayException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param mixed $variableValue 15 | * @param array $array 16 | * @throws InvalidArrayException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $array) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_array($array)) { 24 | throw new InvalidArrayException('array', $array); 25 | } 26 | 27 | parent::__construct( 28 | sprintf( 29 | 'Variable "$%s" must be "in array" {%s}, actual value: "%s"', 30 | $variableName, 31 | print_r($array, true), 32 | print_r($variableValue, true) 33 | ) 34 | ); 35 | } 36 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNumericException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNumericException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int $variableValue 15 | * @throws InvalidIntOrFloatOrStringException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (!is_int($variableValue) && !is_float($variableValue) && !is_string($variableValue)) { 23 | throw new InvalidIntOrFloatOrStringException('variableValue', $variableValue); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "numeric", actual value: "%s"', 29 | $variableName, 30 | (string) $variableValue 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidIntOrFloatException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidIntOrFloatException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|bool|null|resource|string $variableValue 15 | * @throws InvalidNotIntAndNotFloatException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_int($variableValue) || is_float($variableValue)) { 23 | throw new InvalidNotIntAndNotFloatException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "int" or "float", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidNullOrIntException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNullOrIntException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string|float|bool|resource|array $variableValue 15 | * @throws InvalidNotEmptyException 16 | * @throws InvalidNotNullAndNotIntException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (is_null($variableValue) || is_int($variableValue)) { 24 | throw new InvalidNotNullAndNotIntException($variableName); 25 | } 26 | 27 | parent::__construct( 28 | sprintf( 29 | 'Variable "$%s" must be: "null" or "int", actual type: "%s"', 30 | $variableName, 31 | gettype($variableValue) 32 | ) 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/exceptions/InvalidIntOrStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidIntOrStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float|bool|resource|array $variableValue 15 | * @throws InvalidNotIntAndNotStringException 16 | * @throws InvalidNotEmptyException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (is_int($variableValue) || is_string($variableValue)) { 24 | throw new InvalidNotIntAndNotStringException($variableName); 25 | } 26 | 27 | parent::__construct( 28 | sprintf( 29 | 'Variable "$%s" must be: "int" or "string", actual type: "%s"', 30 | $variableName, 31 | gettype($variableValue) 32 | ) 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/exceptions/InvalidNullOrStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidNullOrStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float|bool|resource|array $variableValue 15 | * @throws InvalidNotEmptyException 16 | * @throws InvalidNotNullAndNotStringException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (is_null($variableValue) || is_string($variableValue)) { 24 | throw new InvalidNotNullAndNotStringException($variableName); 25 | } 26 | 27 | parent::__construct( 28 | sprintf( 29 | 'Variable "$%s" must be: "null" or "string", actual type: "%s"', 30 | $variableName, 31 | gettype($variableValue) 32 | ) 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/exceptions/StringNotMatchGlobException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class StringNotMatchGlobException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @param string $pattern 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue, $pattern) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (!is_string($variableValue)) { 23 | throw new InvalidStringException('variableValue', $variableValue); 24 | } elseif (!is_string($pattern)) { 25 | throw new InvalidStringException('pattern', $pattern); 26 | } 27 | 28 | parent::__construct( 29 | sprintf( 30 | 'Variable "$%s" must match glob pattern "%s", actual value: "%s"', 31 | $variableName, 32 | $pattern, 33 | $variableValue 34 | ) 35 | ); 36 | } 37 | } -------------------------------------------------------------------------------- /src/exceptions/StringNotMatchRegExpException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class StringNotMatchRegExpException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @param string $pattern 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue, $pattern) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (!is_string($variableValue)) { 23 | throw new InvalidStringException('variableValue', $variableValue); 24 | } elseif (!is_string($pattern)) { 25 | throw new InvalidStringException('pattern', $pattern); 26 | } 27 | 28 | parent::__construct( 29 | sprintf( 30 | 'Variable "$%s" must match RegExp pattern "%s", actual value: "%s"', 31 | $variableName, 32 | $pattern, 33 | $variableValue 34 | ) 35 | ); 36 | } 37 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidIntOrFloatOrStringException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidIntOrFloatOrStringException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array|bool|null|resource|string $variableValue 15 | * @throws InvalidNotIntAndNotFloatAndNotStringException 16 | * @throws InvalidStringException 17 | */ 18 | public function __construct($variableName, $variableValue) 19 | { 20 | if (!is_string($variableName)) { 21 | throw new InvalidStringException('variableName', $variableName); 22 | } elseif (is_int($variableValue) || is_float($variableValue) || is_string($variableValue)) { 23 | throw new InvalidNotIntAndNotFloatAndNotStringException('variableValue'); 24 | } 25 | 26 | parent::__construct( 27 | sprintf( 28 | 'Variable "$%s" must be "int" or "float" or "string", actual type: "%s"', 29 | $variableName, 30 | gettype($variableValue) 31 | ) 32 | ); 33 | } 34 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidStringLengthException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidStringLengthException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @param int $length 16 | * @throws InvalidIntException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $length) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_string($variableValue)) { 24 | throw new InvalidStringException('variableValue', $variableValue); 25 | } elseif (!is_int($length)) { 26 | throw new InvalidIntException('length', $length); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must have length "%d", actual length: "%d"', 32 | $variableName, 33 | $length, 34 | mb_strlen($variableValue) 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/LengthNotLessException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class LengthNotLessException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @param int $length 16 | * @throws InvalidIntException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $length) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_string($variableValue)) { 24 | throw new InvalidStringException('variableValue', $variableValue); 25 | } elseif (!is_int($length)) { 26 | throw new InvalidIntException('length', $length); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must have length less than "%d", actual length: "%d"', 32 | $variableName, 33 | $length, 34 | mb_strlen($variableValue) 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/LengthNotGreaterException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class LengthNotGreaterException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @param int $length 16 | * @throws InvalidIntException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $length) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_string($variableValue)) { 24 | throw new InvalidStringException('variableValue', $variableValue); 25 | } elseif (!is_int($length)) { 26 | throw new InvalidIntException('length', $length); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must have length greater than "%d", actual length: "%d"', 32 | $variableName, 33 | $length, 34 | mb_strlen($variableValue) 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/InvalidSameValueException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidSameValueException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float|bool|resource|array $variableValue 15 | * @param int|float|bool|resource|array $anotherValue 16 | * @throws InvalidNotEmptyException 17 | * @throws InvalidStringException 18 | * @throws InvalidNotSameValueException 19 | */ 20 | public function __construct($variableName, $variableValue, $anotherValue) 21 | { 22 | if (!is_string($variableName)) { 23 | throw new InvalidStringException('variableName', $variableName); 24 | } elseif ($variableValue === $anotherValue) { 25 | throw new InvalidNotSameValueException('variableValue', $variableValue); 26 | } 27 | 28 | parent::__construct( 29 | sprintf( 30 | 'Variable "$%s" must be same as: "%s", actual value: "%s"', 31 | $variableName, 32 | print_r($anotherValue, true), 33 | print_r($variableValue, true) 34 | ) 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/exceptions/NumberNotLessException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotLessException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @param int|float $number 16 | * @throws InvalidIntOrFloatException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $number) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 24 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 25 | } elseif (!is_int($number) && !is_float($number)) { 26 | throw new InvalidIntOrFloatException('number', $number); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must be less than "%s", actual value: "%s"', 32 | $variableName, 33 | (string) $number, 34 | (string) $variableValue 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/NumberNotGreaterException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotGreaterException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @param int|float $number 16 | * @throws InvalidIntOrFloatException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $number) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 24 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 25 | } elseif (!is_int($number) && !is_float($number)) { 26 | throw new InvalidIntOrFloatException('number', $number); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must be greater than "%s", actual value: "%s"', 32 | $variableName, 33 | (string) $number, 34 | (string) $variableValue 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/NumberNotLessStrictlyException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotLessStrictlyException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @param int|float $number 16 | * @throws InvalidIntOrFloatException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $number) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 24 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 25 | } elseif (!is_int($number) && !is_float($number)) { 26 | throw new InvalidIntOrFloatException('number', $number); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must be strictly less than "%s", actual value: "%s"', 32 | $variableName, 33 | (string) $number, 34 | (string) $variableValue 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/NumberNotGreaterStrictlyException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotGreaterStrictlyException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @param int|float $number 16 | * @throws InvalidIntOrFloatException 17 | * @throws InvalidStringException 18 | */ 19 | public function __construct($variableName, $variableValue, $number) 20 | { 21 | if (!is_string($variableName)) { 22 | throw new InvalidStringException('variableName', $variableName); 23 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 24 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 25 | } elseif (!is_int($number) && !is_float($number)) { 26 | throw new InvalidIntOrFloatException('number', $number); 27 | } 28 | 29 | parent::__construct( 30 | sprintf( 31 | 'Variable "$%s" must be strictly greater than "%s", actual value: "%s"', 32 | $variableName, 33 | (string) $number, 34 | (string) $variableValue 35 | ) 36 | ); 37 | } 38 | } -------------------------------------------------------------------------------- /src/exceptions/LengthNotBetweenException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class LengthNotBetweenException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param string $variableValue 15 | * @param int $from 16 | * @param int $to 17 | * @throws InvalidIntException 18 | * @throws InvalidStringException 19 | */ 20 | public function __construct($variableName, $variableValue, $from, $to) 21 | { 22 | if (!is_string($variableName)) { 23 | throw new InvalidStringException('variableName', $variableName); 24 | } elseif (!is_string($variableValue)) { 25 | throw new InvalidStringException('variableValue', $variableValue); 26 | } elseif (!is_int($from)) { 27 | throw new InvalidIntException('from', $from); 28 | } elseif (!is_int($to)) { 29 | throw new InvalidIntException('to', $to); 30 | } 31 | 32 | parent::__construct( 33 | sprintf( 34 | 'Variable "$%s" must have length between "%d" and "%d", actual length: "%d"', 35 | $variableName, 36 | $from, 37 | $to, 38 | mb_strlen($variableValue) 39 | ) 40 | ); 41 | } 42 | } -------------------------------------------------------------------------------- /.provision/files/dot/.bash_aliases: -------------------------------------------------------------------------------- 1 | if [ -f /etc/bash_completion ]; then 2 | source /etc/bash_completion 3 | fi 4 | 5 | __has_parent_dir () { 6 | # Utility function so we can test for things like .git/.hg without firing up a 7 | # separate process 8 | test -d "$1" && return 0; 9 | 10 | current="." 11 | while [ ! "$current" -ef "$current/.." ]; do 12 | if [ -d "$current/$1" ]; then 13 | return 0; 14 | fi 15 | current="$current/.."; 16 | done 17 | 18 | return 1; 19 | } 20 | 21 | __vcs_name() { 22 | if [ -d .svn ]; then 23 | echo "-[svn]"; 24 | elif __has_parent_dir ".git"; then 25 | echo "-[$(__git_ps1 'git %s')]"; 26 | elif __has_parent_dir ".hg"; then 27 | echo "-[hg $(hg branch)]" 28 | fi 29 | } 30 | 31 | black=$(tput -Txterm setaf 0) 32 | red=$(tput -Txterm setaf 1) 33 | green=$(tput -Txterm setaf 2) 34 | yellow=$(tput -Txterm setaf 3) 35 | dk_blue=$(tput -Txterm setaf 4) 36 | pink=$(tput -Txterm setaf 5) 37 | lt_blue=$(tput -Txterm setaf 6) 38 | 39 | bold=$(tput -Txterm bold) 40 | reset=$(tput -Txterm sgr0) 41 | 42 | # Nicely formatted terminal prompt 43 | export PS1='\n\[$bold\]\[$black\][\[$dk_blue\]\@\[$black\]]-[\[$green\]\u\[$yellow\]@\[$green\]\h\[$black\]]-[\[$pink\]\w\[$black\]]\[\033[0;33m\]$(__vcs_name) \[\033[00m\]\[$reset\]\n\[$reset\]\$ ' 44 | 45 | alias ls='ls -F --color=always' 46 | alias dir='dir -F --color=always' 47 | alias ll='ls -l' 48 | alias cp='cp -iv' 49 | alias rm='rm -i' 50 | alias mv='mv -iv' 51 | alias grep='grep --color=auto -in' 52 | alias ..='cd ..' 53 | 54 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidEmptyExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidEmptyException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidEmptyExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidEmptyException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidEmptyException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "empty"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotIntExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotIntException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotIntExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotIntException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotIntException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not int"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotBoolExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotBoolException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotBoolExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotBoolException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotBoolException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not bool"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotNullExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotNullException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotNullExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotNullException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotNullException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not null"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/exceptions/InvalidArrayCountException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class InvalidArrayCountException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param array $variableValue 15 | * @param int $count 16 | * @throws InvalidArrayException 17 | * @throws InvalidIntException 18 | * @throws InvalidNotEmptyException 19 | * @throws InvalidStringException 20 | * @throws NumberNotGreaterException 21 | */ 22 | public function __construct($variableName, $variableValue, $count) 23 | { 24 | if (!is_string($variableName)) { 25 | throw new InvalidStringException('variableName', $variableName); 26 | } elseif (!is_array($variableValue)) { 27 | throw new InvalidArrayException('variableValue', $variableValue); 28 | } elseif (!is_int($count)) { 29 | throw new InvalidIntException('count', $count); 30 | } elseif ($count < 0) { 31 | throw new NumberNotGreaterException('count', $count, 0); 32 | } 33 | 34 | parent::__construct( 35 | sprintf( 36 | 'Variable "$%s" must contain: "%d" elements, actual count: "%d"', 37 | $variableName, 38 | $count, 39 | count($variableValue) 40 | ) 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotArrayExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotArrayException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotArrayExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotArrayException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotArrayException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not array"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotEmptyExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotEmptyException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotEmptyExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotEmptyException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotEmptyException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not empty"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotFloatExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotFloatExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotFloatException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotFloatException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not float"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotStringException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotStringExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotStringException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotStringException(self::INT_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not string"', 40 | self::INT_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotObjectExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotObjectException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotObjectExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotObjectException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotObjectException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not object"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotResourceExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotResourceException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotResourceExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotResourceException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotResourceException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not resource"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/exceptions/NumberNotBetweenException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotBetweenException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @param int|float $from 16 | * @param int|float $to 17 | * @throws InvalidIntOrFloatException 18 | * @throws InvalidStringException 19 | */ 20 | public function __construct($variableName, $variableValue, $from, $to) 21 | { 22 | if (!is_string($variableName)) { 23 | throw new InvalidStringException('variableName', $variableName); 24 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 25 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 26 | } elseif (!is_int($from) && !is_float($from)) { 27 | throw new InvalidIntOrFloatException('from', $from); 28 | } elseif (!is_int($to) && !is_float($to)) { 29 | throw new InvalidIntOrFloatException('to', $to); 30 | } 31 | 32 | parent::__construct( 33 | sprintf( 34 | 'Variable "$%s" must be between "%s" and "%s", actual value: "%s"', 35 | $variableName, 36 | (string) $from, 37 | (string) $to, 38 | (string) $variableValue 39 | ) 40 | ); 41 | } 42 | } -------------------------------------------------------------------------------- /src/exceptions/NumberNotBetweenStrictlyException.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\exceptions; 9 | 10 | class NumberNotBetweenStrictlyException extends ArgumentException 11 | { 12 | /** 13 | * @param string $variableName 14 | * @param int|float $variableValue 15 | * @param int|float $from 16 | * @param int|float $to 17 | * @throws InvalidIntOrFloatException 18 | * @throws InvalidStringException 19 | */ 20 | public function __construct($variableName, $variableValue, $from, $to) 21 | { 22 | if (!is_string($variableName)) { 23 | throw new InvalidStringException('variableName', $variableName); 24 | } elseif (!is_int($variableValue) && !is_float($variableValue)) { 25 | throw new InvalidIntOrFloatException('variableValue', $variableValue); 26 | } elseif (!is_int($from) && !is_float($from)) { 27 | throw new InvalidIntOrFloatException('from', $from); 28 | } elseif (!is_int($to) && !is_float($to)) { 29 | throw new InvalidIntOrFloatException('to', $to); 30 | } 31 | 32 | parent::__construct( 33 | sprintf( 34 | 'Variable "$%s" must be strictly between "%s" and "%s", actual value: "%s"', 35 | $variableName, 36 | (string) $from, 37 | (string) $to, 38 | (string) $variableValue 39 | ) 40 | ); 41 | } 42 | } -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotNullAndNotIntExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotNullAndNotIntException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotNullAndNotIntExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotNullAndNotIntException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotNullAndNotIntException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not null" and "not int"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotIntAndNotFloatExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotIntAndNotFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotIntAndNotFloatExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotIntAndNotFloatException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotIntAndNotFloatException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not int" and "not float"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotIntAndNotStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotIntAndNotStringException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotIntAndNotStringExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotIntAndNotStringException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotIntAndNotStringException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not int" and "not string"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotNullAndNotStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotNullAndNotStringException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotNullAndNotStringExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotNullAndNotStringException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotNullAndNotStringException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not null" and "not string"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotIntAndNotFloatAndNotStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotIntAndNotFloatAndNotStringException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotIntAndNotFloatAndNotStringExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotIntAndNotFloatAndNotStringException($typeValue); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $error = new InvalidNotIntAndNotFloatAndNotStringException(self::STRING_FIXTURE); 36 | 37 | $this->assertSame( 38 | sprintf( 39 | 'Variable "$%s" must be "not int" and "not float" and "not string"', 40 | self::STRING_FIXTURE 41 | ), 42 | $error->getMessage() 43 | ); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNotSameValueExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotSameValueException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidNotSameValueExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidNotSameValueException($typeValue, 'data'); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testMessage() 34 | { 35 | $variableName = 'variableName'; 36 | $fixtures = $this->getTypeFixtures(); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $error = new InvalidNotSameValueException($variableName, $typeValue); 40 | 41 | $this->assertSame( 42 | sprintf( 43 | 'Variable "$%s" must be not same as: "%s"', 44 | $variableName, 45 | print_r($typeValue, true) 46 | ), 47 | $error->getMessage() 48 | ); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | filter: 2 | paths: [src/*] 3 | 4 | checks: 5 | php: 6 | code_rating: true 7 | duplication: false 8 | fix_php_opening_tag: true 9 | remove_php_closing_tag: true 10 | one_class_per_file: true 11 | side_effects_or_types: true 12 | no_mixed_inline_html: false 13 | require_braces_around_control_structures: false 14 | php5_style_constructor: true 15 | no_global_keyword: true 16 | avoid_usage_of_logical_operators: true 17 | psr2_class_declaration: true 18 | no_underscore_prefix_in_properties: true 19 | no_underscore_prefix_in_methods: true 20 | blank_line_after_namespace_declaration: true 21 | single_namespace_per_use: true 22 | psr2_switch_declaration: true 23 | psr2_control_structure_declaration: false 24 | avoid_superglobals: false 25 | security_vulnerabilities: true 26 | use_self_instead_of_fqcn: true 27 | uppercase_constants: true 28 | return_doc_comments: true 29 | simplify_boolean_return: true 30 | return_doc_comment_if_not_inferrable: true 31 | remove_extra_empty_lines: true 32 | properties_in_camelcaps: true 33 | prefer_while_loop_over_for_loop: true 34 | phpunit_assertions: true 35 | parameters_in_camelcaps: true 36 | parameter_doc_comments: true 37 | param_doc_comment_if_not_inferrable: true 38 | optional_parameters_at_the_end: true 39 | no_long_variable_names: 40 | maximum: '20' 41 | no_goto: true 42 | newline_at_end_of_file: true 43 | more_specific_types_in_doc_comments: true 44 | function_in_camel_caps: true 45 | fix_use_statements: 46 | remove_unused: true 47 | preserve_multiple: true 48 | preserve_blanklines: true 49 | order_alphabetically: true 50 | fix_line_ending: true 51 | encourage_postdec_operator: true 52 | classes_in_camel_caps: true 53 | avoid_unnecessary_concatenation: true 54 | avoid_todo_comments: true 55 | avoid_perl_style_comments: true 56 | align_assignments: false 57 | 58 | coding_style: 59 | php: { } 60 | 61 | tools: 62 | php_code_sniffer: 63 | config: 64 | standard: "PSR2" 65 | external_code_coverage: 66 | timeout: 600 67 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidDigitExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidDigitException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidDigitExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidDigitException($typeValue, 'data'); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testConstructWithVariableValue() 34 | { 35 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 36 | 37 | foreach ($fixtures as $typeName => $typeValue) { 38 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 39 | 40 | try { 41 | new InvalidDigitException('variableName', $typeValue); 42 | 43 | $this->fail('Not fail with: ' . $expectedMessage); 44 | } catch (InvalidStringException $error) { 45 | $this->assertSame($expectedMessage, $error->getMessage()); 46 | } 47 | } 48 | 49 | new InvalidDigitException('variableValue', $this->getTypeFixture(self::STRING_FIXTURE)); 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 55 | $error = new InvalidDigitException('variableName', $fixture); 56 | 57 | $this->assertSame( 58 | sprintf( 59 | 'Variable "$variableName" must be "digit", actual value: "%s"', 60 | $fixture 61 | ), 62 | $error->getMessage() 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/BaseUnitTestCase.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests; 9 | 10 | class BaseUnitTestCase extends \PHPUnit_Framework_TestCase 11 | { 12 | const NULL_FIXTURE = 'null'; 13 | const BOOL_FIXTURE = 'bool'; 14 | const INT_FIXTURE = 'int'; 15 | const FLOAT_FIXTURE = 'float'; 16 | const STRING_FIXTURE = 'string'; 17 | const ARRAY_FIXTURE = 'array'; 18 | const OBJECT_FIXTURE = 'object'; 19 | const RESOURCE_FIXTURE = 'resource'; 20 | 21 | /** 22 | * @return array 23 | */ 24 | public function getTypeFixtures() 25 | { 26 | return [ 27 | self::NULL_FIXTURE => null, 28 | self::BOOL_FIXTURE => true, 29 | self::INT_FIXTURE => 0, 30 | self::FLOAT_FIXTURE => 0.0, 31 | self::STRING_FIXTURE => '', 32 | self::ARRAY_FIXTURE => [], 33 | self::OBJECT_FIXTURE => new \stdClass, 34 | self::RESOURCE_FIXTURE => stream_context_create(), 35 | ]; 36 | } 37 | 38 | /** 39 | * @param array $fixtureNames 40 | * @return array 41 | * @throws \InvalidArgumentException 42 | */ 43 | public function getTypeFixturesWithout(array $fixtureNames) 44 | { 45 | $result = $this->getTypeFixtures(); 46 | 47 | foreach ($fixtureNames as $typeName) { 48 | if (array_key_exists($typeName, $result) === false) { 49 | throw new \InvalidArgumentException( 50 | sprintf('Unknown type fixture name: "%s"', $typeName) 51 | ); 52 | } 53 | 54 | unset($result[$typeName]); 55 | } 56 | 57 | return $result; 58 | } 59 | 60 | /** 61 | * @param string $fixtureName 62 | * @return mixed 63 | * @throws \InvalidArgumentException 64 | */ 65 | public function getTypeFixture($fixtureName) 66 | { 67 | $result = $this->getTypeFixtures(); 68 | 69 | if (array_key_exists($fixtureName, $result) === false) { 70 | throw new \InvalidArgumentException( 71 | sprintf('Unknown type fixture name: "%s"', $fixtureName) 72 | ); 73 | } 74 | 75 | return $result[$fixtureName]; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /tests/unit/exceptions/ArrayKeyNotExistsExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\ArrayKeyNotExistsException; 11 | use KoKoKo\assert\exceptions\InvalidIntOrStringException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class ArrayKeyNotExistsExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new ArrayKeyNotExistsException($typeValue, 'variableName'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithKey() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::STRING_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrStringException('key', $typeValue))->getMessage(); 40 | 41 | try { 42 | new ArrayKeyNotExistsException('variableName', $typeValue); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrStringException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | } 50 | 51 | public function testMessage() 52 | { 53 | $variableName = 'variableName'; 54 | $key = 'keyName'; 55 | $error = new ArrayKeyNotExistsException($variableName, $key); 56 | 57 | $this->assertSame( 58 | sprintf( 59 | 'Variable "$%s" must contain key: "%s"', 60 | $variableName, 61 | $key 62 | ), 63 | $error->getMessage() 64 | ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNullExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotNullException; 11 | use KoKoKo\assert\exceptions\InvalidNullException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidNullExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidNullException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtureName = self::NULL_FIXTURE; 37 | $expectedMessage = (new InvalidNotNullException('variableValue'))->getMessage(); 38 | 39 | try { 40 | new InvalidNullException('variableName', $this->getTypeFixture($fixtureName)); 41 | 42 | $this->fail('Not fail with: ' . $expectedMessage); 43 | } catch (InvalidNotNullException $error) { 44 | $this->assertSame($expectedMessage, $error->getMessage()); 45 | } 46 | 47 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 48 | new InvalidNullException('variableName', $typeValue); 49 | } 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 55 | $error = new InvalidNullException('variableName', $fixture); 56 | 57 | $this->assertSame( 58 | sprintf( 59 | 'Variable "$variableName" must be "null", actual type: "%s"', 60 | self::STRING_FIXTURE 61 | ), 62 | $error->getMessage() 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidRegExpPatternExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidRegExpPatternException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidRegExpPatternExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidRegExpPatternException($typeValue, 'data'); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testConstructWithVariableValue() 34 | { 35 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 36 | 37 | foreach ($fixtures as $typeName => $typeValue) { 38 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 39 | 40 | try { 41 | new InvalidRegExpPatternException('variableName', $typeValue); 42 | 43 | $this->fail('Not fail with: ' . $expectedMessage); 44 | } catch (InvalidStringException $error) { 45 | $this->assertSame($expectedMessage, $error->getMessage()); 46 | } 47 | } 48 | 49 | new InvalidRegExpPatternException('variableValue', $this->getTypeFixture(self::STRING_FIXTURE)); 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 55 | $error = new InvalidRegExpPatternException('variableName', $fixture); 56 | 57 | $this->assertSame( 58 | sprintf( 59 | 'Variable "$variableName" must be "correct RegExp pattern", actual value: "%s"', 60 | $fixture 61 | ), 62 | $error->getMessage() 63 | ); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /tests/unit/exceptions/ValueNotInArrayExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidArrayException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\ValueNotInArrayException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class ValueNotInArrayExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new ValueNotInArrayException($typeValue, 'variableName', [1]); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithArray() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::ARRAY_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidArrayException('array', $typeValue))->getMessage(); 40 | 41 | try { 42 | new ValueNotInArrayException('variableName', 'variableValue', $typeValue); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidArrayException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | } 50 | 51 | public function testMessage() 52 | { 53 | $value = 'variableValue'; 54 | $fixture = $this->getTypeFixture(self::ARRAY_FIXTURE); 55 | $error = new ValueNotInArrayException('variableName', $value, $fixture); 56 | 57 | $this->assertSame( 58 | sprintf( 59 | 'Variable "$variableName" must be "in array" {%s}, actual value: "%s"', 60 | print_r($fixture, true), 61 | print_r($value, true) 62 | ), 63 | $error->getMessage() 64 | ); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotStringException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class InvalidStringExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new InvalidStringException($typeValue, 'data'); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testConstructWithVariableValue() 34 | { 35 | $fixtureName = self::STRING_FIXTURE; 36 | $expectedMessage = (new InvalidNotStringException('variableValue'))->getMessage(); 37 | 38 | try { 39 | new InvalidStringException('data', $this->getTypeFixture($fixtureName)); 40 | 41 | $this->fail('Not fail with: ' . $expectedMessage); 42 | } catch (InvalidNotStringException $error) { 43 | $this->assertSame($expectedMessage, $error->getMessage()); 44 | } 45 | 46 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 47 | new InvalidStringException('data', $typeValue); 48 | } 49 | } 50 | 51 | public function testMessage() 52 | { 53 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 54 | 55 | foreach ($fixtures as $typeName => $typeValue) { 56 | $error = new InvalidStringException($typeName, $typeValue); 57 | 58 | $this->assertSame( 59 | sprintf( 60 | 'Variable "$%s" must be "string", actual type: "%s"', 61 | $typeName, 62 | gettype($typeValue) 63 | ), 64 | $error->getMessage() 65 | ); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidIntExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntException; 11 | use KoKoKo\assert\exceptions\InvalidNotIntException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidIntExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidIntException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtureName = self::INT_FIXTURE; 37 | $expectedMessage = (new InvalidNotIntException('variableValue'))->getMessage(); 38 | 39 | try { 40 | new InvalidIntException('variableName', $this->getTypeFixture($fixtureName)); 41 | 42 | $this->fail('Not fail with: ' . $expectedMessage); 43 | } catch (InvalidNotIntException $error) { 44 | $this->assertSame($expectedMessage, $error->getMessage()); 45 | } 46 | 47 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 48 | new InvalidIntException('variableName', $typeValue); 49 | } 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 55 | 56 | foreach ($fixtures as $typeName => $typeValue) { 57 | $error = new InvalidIntException($typeName, $typeValue); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "int", actual type: "%s"', 62 | $typeName, 63 | gettype($typeValue) 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidBoolExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidBoolException; 11 | use KoKoKo\assert\exceptions\InvalidNotBoolException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidBoolExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidBoolException($typeValue, 'variableName'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtureName = self::BOOL_FIXTURE; 37 | $expectedMessage = (new InvalidNotBoolException('variableValue'))->getMessage(); 38 | 39 | try { 40 | new InvalidBoolException('variableValue', $this->getTypeFixture($fixtureName)); 41 | 42 | $this->fail('Not fail with: ' . $expectedMessage); 43 | } catch (InvalidNotBoolException $error) { 44 | $this->assertSame($expectedMessage, $error->getMessage()); 45 | } 46 | 47 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 48 | new InvalidBoolException('variableValue', $typeValue); 49 | } 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixtures = $this->getTypeFixturesWithout([self::BOOL_FIXTURE]); 55 | 56 | foreach ($fixtures as $typeName => $typeValue) { 57 | $error = new InvalidBoolException($typeName, $typeValue); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "bool", actual type: "%s"', 62 | $typeName, 63 | gettype($typeValue) 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidArrayExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidArrayException; 11 | use KoKoKo\assert\exceptions\InvalidNotArrayException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidArrayExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidArrayException($typeValue, 'variableName'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtureName = self::ARRAY_FIXTURE; 37 | $expectedMessage = (new InvalidNotArrayException('variableValue'))->getMessage(); 38 | 39 | try { 40 | new InvalidArrayException('variableName', $this->getTypeFixture($fixtureName)); 41 | 42 | $this->fail('Not fail with: ' . $expectedMessage); 43 | } catch (InvalidNotArrayException $error) { 44 | $this->assertSame($expectedMessage, $error->getMessage()); 45 | } 46 | 47 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 48 | new InvalidArrayException('variableName', $typeValue); 49 | } 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixtures = $this->getTypeFixturesWithout([self::ARRAY_FIXTURE]); 55 | 56 | foreach ($fixtures as $typeName => $typeValue) { 57 | $error = new InvalidArrayException($typeName, $typeValue); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "array", actual type: "%s"', 62 | $typeName, 63 | gettype($typeValue) 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidFloatExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidFloatException; 11 | use KoKoKo\assert\exceptions\InvalidNotFloatException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidFloatExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidFloatException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtureName = self::FLOAT_FIXTURE; 37 | $expectedMessage = (new InvalidNotFloatException('variableValue'))->getMessage(); 38 | 39 | try { 40 | new InvalidFloatException('variableName', $this->getTypeFixture($fixtureName)); 41 | 42 | $this->fail('Not fail with: ' . $expectedMessage); 43 | } catch (InvalidNotFloatException $error) { 44 | $this->assertSame($expectedMessage, $error->getMessage()); 45 | } 46 | 47 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 48 | new InvalidFloatException('variableName', $typeValue); 49 | } 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixtures = $this->getTypeFixturesWithout([self::FLOAT_FIXTURE]); 55 | 56 | foreach ($fixtures as $typeName => $typeValue) { 57 | $error = new InvalidFloatException($typeName, $typeValue); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "float", actual type: "%s"', 62 | $typeName, 63 | gettype($typeValue) 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidResourceExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotResourceException; 11 | use KoKoKo\assert\exceptions\InvalidResourceException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidResourceExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidResourceException($typeValue, 'data'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtureName = self::RESOURCE_FIXTURE; 37 | $expectedMessage = (new InvalidNotResourceException('variableValue'))->getMessage(); 38 | 39 | try { 40 | new InvalidResourceException('data', $this->getTypeFixture($fixtureName)); 41 | 42 | $this->fail('Not fail with: ' . $expectedMessage); 43 | } catch (InvalidNotResourceException $error) { 44 | $this->assertSame($expectedMessage, $error->getMessage()); 45 | } 46 | 47 | foreach ($this->getTypeFixturesWithout([$fixtureName]) as $typeName => $typeValue) { 48 | new InvalidResourceException('data', $typeValue); 49 | } 50 | } 51 | 52 | public function testMessage() 53 | { 54 | $fixtures = $this->getTypeFixturesWithout([self::RESOURCE_FIXTURE]); 55 | 56 | foreach ($fixtures as $typeName => $typeValue) { 57 | $error = new InvalidResourceException($typeName, $typeValue); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "resource", actual type: "%s"', 62 | $typeName, 63 | gettype($typeValue) 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotNegativeExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotNegativeException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotNegativeExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotNegativeException($typeValue, -1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotNegativeException('variableName', $typeValue); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotNegativeException('variableValue', $this->getTypeFixture(self::INT_FIXTURE)); 51 | new NumberNotNegativeException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE)); 52 | } 53 | 54 | public function testMessage() 55 | { 56 | $fixture = 10; 57 | $error = new NumberNotNegativeException(self::STRING_FIXTURE, $fixture); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "negative", actual value: "%s"', 62 | self::STRING_FIXTURE, 63 | $fixture 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotPositiveExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotPositiveException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotPositiveExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotPositiveException($typeValue, 'data'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotPositiveException('variableName', $typeValue); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotPositiveException('variableValue', $this->getTypeFixture(self::INT_FIXTURE)); 51 | new NumberNotPositiveException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE)); 52 | } 53 | 54 | public function testMessage() 55 | { 56 | $fixture = -10; 57 | $error = new NumberNotPositiveException(self::STRING_FIXTURE, $fixture); 58 | 59 | $this->assertSame( 60 | sprintf( 61 | 'Variable "$%s" must be "positive", actual value: "%s"', 62 | self::STRING_FIXTURE, 63 | (string) $fixture 64 | ), 65 | $error->getMessage() 66 | ); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNumericExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatOrStringException; 11 | use KoKoKo\assert\exceptions\InvalidNumericException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidNumericExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidNumericException($typeValue, 'variableName'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout( 37 | [self::INT_FIXTURE, self::FLOAT_FIXTURE, self::STRING_FIXTURE] 38 | ); 39 | 40 | foreach ($fixtures as $typeName => $typeValue) { 41 | $expectedMessage = (new InvalidIntOrFloatOrStringException('variableValue', $typeValue))->getMessage(); 42 | 43 | try { 44 | new InvalidNumericException('variableName', $typeValue, 1); 45 | 46 | $this->fail('Not fail with: ' . $expectedMessage); 47 | } catch (InvalidIntOrFloatOrStringException $error) { 48 | $this->assertSame($expectedMessage, $error->getMessage()); 49 | } 50 | } 51 | 52 | new InvalidNumericException('variableValue', $this->getTypeFixture(self::INT_FIXTURE)); 53 | new InvalidNumericException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE)); 54 | new InvalidNumericException('variableValue', $this->getTypeFixture(self::STRING_FIXTURE)); 55 | } 56 | 57 | public function testMessage() 58 | { 59 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 60 | $error = new InvalidNumericException('variableName', $fixture); 61 | 62 | $this->assertSame( 63 | sprintf( 64 | 'Variable "$variableName" must be "numeric", actual value: "%s"', 65 | (string) $fixture 66 | ), 67 | $error->getMessage() 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidSameValueExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotSameValueException; 11 | use KoKoKo\assert\exceptions\InvalidSameValueException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidSameValueExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidSameValueException($typeValue, 'data1', 'data2'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValueAndAnotherValue() 35 | { 36 | $fixtures = $this->getTypeFixtures(); 37 | 38 | foreach ($fixtures as $variableValue) { 39 | foreach ($fixtures as $anotherValue) { 40 | if ($variableValue !== $anotherValue) { 41 | new InvalidSameValueException('data', $variableValue, $anotherValue); 42 | } else { 43 | $expectedMessage = (new InvalidNotSameValueException('variableValue', $variableValue)) 44 | ->getMessage(); 45 | 46 | try { 47 | new InvalidSameValueException('data', $variableValue, $anotherValue); 48 | 49 | $this->fail('Not fail with: ' . $expectedMessage); 50 | } catch (InvalidNotSameValueException $error) { 51 | $this->assertSame($expectedMessage, $error->getMessage()); 52 | } 53 | } 54 | } 55 | } 56 | } 57 | 58 | public function testMessage() 59 | { 60 | $variableName = 'variableName'; 61 | $variableValue = $this->getTypeFixture(self::INT_FIXTURE); 62 | $anotherValue = $this->getTypeFixture(self::BOOL_FIXTURE); 63 | 64 | $error = new InvalidSameValueException($variableName, $variableValue, $anotherValue); 65 | 66 | $this->assertSame( 67 | sprintf( 68 | 'Variable "$%s" must be same as: "%s", actual value: "%s"', 69 | $variableName, 70 | print_r($anotherValue, true), 71 | print_r($variableValue, true) 72 | ), 73 | $error->getMessage() 74 | ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNullOrIntExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotNullAndNotIntException; 11 | use KoKoKo\assert\exceptions\InvalidNullOrIntException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidNullOrIntExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidNullOrIntException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $expectedMessage = (new InvalidNotNullAndNotIntException('variableName'))->getMessage(); 37 | 38 | try { 39 | new InvalidNullOrIntException('variableName', $this->getTypeFixture(self::NULL_FIXTURE)); 40 | 41 | $this->fail('Not fail with: ' . $expectedMessage); 42 | } catch (InvalidNotNullAndNotIntException $error) { 43 | $this->assertSame($expectedMessage, $error->getMessage()); 44 | } 45 | 46 | try { 47 | new InvalidNullOrIntException('variableName', $this->getTypeFixture(self::INT_FIXTURE)); 48 | 49 | $this->fail('Not fail with: ' . $expectedMessage); 50 | } catch (InvalidNotNullAndNotIntException $error) { 51 | $this->assertSame($expectedMessage, $error->getMessage()); 52 | } 53 | 54 | $fixtureTypes = [self::NULL_FIXTURE, self::INT_FIXTURE]; 55 | 56 | foreach ($this->getTypeFixturesWithout($fixtureTypes) as $typeName => $typeValue) { 57 | new InvalidNullOrIntException('variableName', $typeValue); 58 | } 59 | } 60 | 61 | public function testMessage() 62 | { 63 | $fixtures = $this->getTypeFixturesWithout([self::NULL_FIXTURE, self::INT_FIXTURE]); 64 | 65 | foreach ($fixtures as $typeName => $typeValue) { 66 | $error = new InvalidNullOrIntException($typeName, $typeValue); 67 | 68 | $this->assertSame( 69 | sprintf( 70 | 'Variable "$%s" must be: "null" or "int", actual type: "%s"', 71 | $typeName, 72 | gettype($typeValue) 73 | ), 74 | $error->getMessage() 75 | ); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidIntOrFloatExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidNotIntAndNotFloatException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidIntOrFloatExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidIntOrFloatException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $expectedMessage = (new InvalidNotIntAndNotFloatException('variableValue'))->getMessage(); 37 | 38 | try { 39 | new InvalidIntOrFloatException('variableName', $this->getTypeFixture(self::INT_FIXTURE)); 40 | 41 | $this->fail('Not fail with: ' . $expectedMessage); 42 | } catch (InvalidNotIntAndNotFloatException $error) { 43 | $this->assertSame($expectedMessage, $error->getMessage()); 44 | } 45 | 46 | try { 47 | new InvalidIntOrFloatException('variableName', $this->getTypeFixture(self::FLOAT_FIXTURE)); 48 | 49 | $this->fail('Not fail with: ' . $expectedMessage); 50 | } catch (InvalidNotIntAndNotFloatException $error) { 51 | $this->assertSame($expectedMessage, $error->getMessage()); 52 | } 53 | 54 | $fixtureTypes = [self::INT_FIXTURE, self::FLOAT_FIXTURE]; 55 | 56 | foreach ($this->getTypeFixturesWithout($fixtureTypes) as $typeName => $typeValue) { 57 | new InvalidIntOrFloatException('variableName', $typeValue); 58 | } 59 | } 60 | 61 | public function testMessage() 62 | { 63 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 64 | 65 | foreach ($fixtures as $typeName => $typeValue) { 66 | $error = new InvalidIntOrFloatException($typeName, $typeValue); 67 | 68 | $this->assertSame( 69 | sprintf( 70 | 'Variable "$%s" must be "int" or "float", actual type: "%s"', 71 | $typeName, 72 | gettype($typeValue) 73 | ), 74 | $error->getMessage() 75 | ); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidIntOrStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrStringException; 11 | use KoKoKo\assert\exceptions\InvalidNotIntAndNotStringException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidIntOrStringExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidIntOrStringException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $expectedMessage = (new InvalidNotIntAndNotStringException('variableName'))->getMessage(); 37 | 38 | try { 39 | new InvalidIntOrStringException('variableName', $this->getTypeFixture(self::INT_FIXTURE)); 40 | 41 | $this->fail('Not fail with: ' . $expectedMessage); 42 | } catch (InvalidNotIntAndNotStringException $error) { 43 | $this->assertSame($expectedMessage, $error->getMessage()); 44 | } 45 | 46 | try { 47 | new InvalidIntOrStringException('variableName', $this->getTypeFixture(self::STRING_FIXTURE)); 48 | 49 | $this->fail('Not fail with: ' . $expectedMessage); 50 | } catch (InvalidNotIntAndNotStringException $error) { 51 | $this->assertSame($expectedMessage, $error->getMessage()); 52 | } 53 | 54 | $fixtureTypes = [self::INT_FIXTURE, self::STRING_FIXTURE]; 55 | 56 | foreach ($this->getTypeFixturesWithout($fixtureTypes) as $typeName => $typeValue) { 57 | new InvalidIntOrStringException('variableName', $typeValue); 58 | } 59 | } 60 | 61 | public function testMessage() 62 | { 63 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::STRING_FIXTURE]); 64 | 65 | foreach ($fixtures as $typeName => $typeValue) { 66 | $error = new InvalidIntOrStringException($typeName, $typeValue); 67 | 68 | $this->assertSame( 69 | sprintf( 70 | 'Variable "$%s" must be: "int" or "string", actual type: "%s"', 71 | $typeName, 72 | gettype($typeValue) 73 | ), 74 | $error->getMessage() 75 | ); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidNullOrStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidNotNullAndNotStringException; 11 | use KoKoKo\assert\exceptions\InvalidNullOrStringException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidNullOrStringExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidNullOrStringException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $expectedMessage = (new InvalidNotNullAndNotStringException('variableName'))->getMessage(); 37 | 38 | try { 39 | new InvalidNullOrStringException('variableName', $this->getTypeFixture(self::NULL_FIXTURE)); 40 | 41 | $this->fail('Not fail with: ' . $expectedMessage); 42 | } catch (InvalidNotNullAndNotStringException $error) { 43 | $this->assertSame($expectedMessage, $error->getMessage()); 44 | } 45 | 46 | try { 47 | new InvalidNullOrStringException('variableName', $this->getTypeFixture(self::STRING_FIXTURE)); 48 | 49 | $this->fail('Not fail with: ' . $expectedMessage); 50 | } catch (InvalidNotNullAndNotStringException $error) { 51 | $this->assertSame($expectedMessage, $error->getMessage()); 52 | } 53 | 54 | $fixtureTypes = [self::NULL_FIXTURE, self::STRING_FIXTURE]; 55 | 56 | foreach ($this->getTypeFixturesWithout($fixtureTypes) as $typeName => $typeValue) { 57 | new InvalidNullOrStringException('variableName', $typeValue); 58 | } 59 | } 60 | 61 | public function testMessage() 62 | { 63 | $fixtures = $this->getTypeFixturesWithout([self::NULL_FIXTURE, self::STRING_FIXTURE]); 64 | 65 | foreach ($fixtures as $typeName => $typeValue) { 66 | $error = new InvalidNullOrStringException($typeName, $typeValue); 67 | 68 | $this->assertSame( 69 | sprintf( 70 | 'Variable "$%s" must be: "null" or "string", actual type: "%s"', 71 | $typeName, 72 | gettype($typeValue) 73 | ), 74 | $error->getMessage() 75 | ); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidIntOrFloatOrStringExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatOrStringException; 11 | use KoKoKo\assert\exceptions\InvalidNotIntAndNotFloatAndNotStringException; 12 | use KoKoKo\assert\exceptions\InvalidStringException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidIntOrFloatOrStringExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidIntOrFloatOrStringException($typeValue, 'variableValue'); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $expectedMessage = (new InvalidNotIntAndNotFloatAndNotStringException('variableValue'))->getMessage(); 37 | 38 | try { 39 | new InvalidIntOrFloatOrStringException('variableName', $this->getTypeFixture(self::INT_FIXTURE)); 40 | 41 | $this->fail('Not fail with: ' . $expectedMessage); 42 | } catch (InvalidNotIntAndNotFloatAndNotStringException $error) { 43 | $this->assertSame($expectedMessage, $error->getMessage()); 44 | } 45 | 46 | try { 47 | new InvalidIntOrFloatOrStringException('variableName', $this->getTypeFixture(self::FLOAT_FIXTURE)); 48 | 49 | $this->fail('Not fail with: ' . $expectedMessage); 50 | } catch (InvalidNotIntAndNotFloatAndNotStringException $error) { 51 | $this->assertSame($expectedMessage, $error->getMessage()); 52 | } 53 | 54 | $fixtureTypes = [self::INT_FIXTURE, self::FLOAT_FIXTURE, self::STRING_FIXTURE]; 55 | 56 | foreach ($this->getTypeFixturesWithout($fixtureTypes) as $typeName => $typeValue) { 57 | new InvalidIntOrFloatOrStringException('variableName', $typeValue); 58 | } 59 | } 60 | 61 | public function testMessage() 62 | { 63 | $fixtures = $this->getTypeFixturesWithout( 64 | [self::INT_FIXTURE, self::FLOAT_FIXTURE, self::STRING_FIXTURE] 65 | ); 66 | 67 | foreach ($fixtures as $typeName => $typeValue) { 68 | $error = new InvalidIntOrFloatOrStringException($typeName, $typeValue); 69 | 70 | $this->assertSame( 71 | sprintf( 72 | 'Variable "$%s" must be "int" or "float" or "string", actual type: "%s"', 73 | $typeName, 74 | gettype($typeValue) 75 | ), 76 | $error->getMessage() 77 | ); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /tests/unit/exceptions/LengthNotLessExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\LengthNotLessException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class LengthNotLessExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new LengthNotLessException($typeValue, 'variableValue', 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new LengthNotLessException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidStringException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new LengthNotLessException('variableName', $this->getTypeFixture(self::STRING_FIXTURE), 1); 51 | } 52 | 53 | public function testConstructThirdArgument() 54 | { 55 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 56 | 57 | foreach ($fixtures as $typeName => $typeValue) { 58 | $expectedMessage = (new InvalidIntException('length', $typeValue))->getMessage(); 59 | 60 | try { 61 | new LengthNotLessException('variableName', 'variableValue', $typeValue); 62 | 63 | $this->fail('Not fail with: ' . $expectedMessage); 64 | } catch (InvalidIntException $error) { 65 | $this->assertSame($expectedMessage, $error->getMessage()); 66 | } 67 | } 68 | 69 | new LengthNotLessException( 70 | 'variableName', 'variableValue', $this->getTypeFixture(self::INT_FIXTURE) 71 | ); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $length = 10; 77 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 78 | $error = new LengthNotLessException('variableName', $fixture, $length); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must have length less than "%s", actual length: "%s"', 83 | (string) $length, 84 | mb_strlen($fixture) 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/LengthNotGreaterExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\LengthNotGreaterException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class LengthNotGreaterExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new LengthNotGreaterException($typeValue, 'variableValue', 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new LengthNotGreaterException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidStringException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new LengthNotGreaterException('variableName', $this->getTypeFixture(self::STRING_FIXTURE), 1); 51 | } 52 | 53 | public function testConstructWithLength() 54 | { 55 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 56 | 57 | foreach ($fixtures as $typeName => $typeValue) { 58 | $expectedMessage = (new InvalidIntException('length', $typeValue))->getMessage(); 59 | 60 | try { 61 | new LengthNotGreaterException('variableName', 'variableValue', $typeValue); 62 | 63 | $this->fail('Not fail with: ' . $expectedMessage); 64 | } catch (InvalidIntException $error) { 65 | $this->assertSame($expectedMessage, $error->getMessage()); 66 | } 67 | } 68 | 69 | new LengthNotGreaterException( 70 | 'variableName', 'variableValue', $this->getTypeFixture(self::INT_FIXTURE) 71 | ); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $length = 10; 77 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 78 | $error = new LengthNotGreaterException('variableName', $fixture, $length); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must have length greater than "%s", actual length: "%s"', 83 | (string) $length, 84 | mb_strlen($fixture) 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidStringLengthExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\InvalidStringLengthException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class InvalidStringLengthExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new InvalidStringLengthException($typeValue, 'variableValue', 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new InvalidStringLengthException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidStringException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new InvalidStringLengthException('variableName', $this->getTypeFixture(self::STRING_FIXTURE), 1); 51 | } 52 | 53 | public function testConstructWithLength() 54 | { 55 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 56 | 57 | foreach ($fixtures as $typeName => $typeValue) { 58 | $expectedMessage = (new InvalidIntException('length', $typeValue))->getMessage(); 59 | 60 | try { 61 | new InvalidStringLengthException('variableName', 'variableValue', $typeValue); 62 | 63 | $this->fail('Not fail with: ' . $expectedMessage); 64 | } catch (InvalidIntException $error) { 65 | $this->assertSame($expectedMessage, $error->getMessage()); 66 | } 67 | } 68 | 69 | new InvalidStringLengthException( 70 | 'variableName', 'variableValue', $this->getTypeFixture(self::INT_FIXTURE) 71 | ); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $length = 10; 77 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 78 | $error = new InvalidStringLengthException('variableName', $fixture, $length); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must have length "%s", actual length: "%s"', 83 | (string) $length, 84 | mb_strlen($fixture) 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/StringNotMatchGlobExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidStringException; 11 | use KoKoKo\assert\exceptions\StringNotMatchGlobException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class StringNotMatchGlobExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new StringNotMatchGlobException($typeValue, 1, 1); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testConstructWithVariableValue() 34 | { 35 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 36 | 37 | foreach ($fixtures as $typeName => $typeValue) { 38 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 39 | 40 | try { 41 | new StringNotMatchGlobException('variableName', $typeValue, 'pattern'); 42 | 43 | $this->fail('Not fail with: ' . $expectedMessage); 44 | } catch (InvalidStringException $error) { 45 | $this->assertSame($expectedMessage, $error->getMessage()); 46 | } 47 | } 48 | 49 | new StringNotMatchGlobException( 50 | 'variableName', $this->getTypeFixture(self::STRING_FIXTURE), 'pattern' 51 | ); 52 | } 53 | 54 | public function testConstructWithPattern() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidStringException('pattern', $typeValue))->getMessage(); 60 | 61 | try { 62 | new StringNotMatchGlobException('variableName', 'variableValue', $typeValue); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidStringException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new StringNotMatchGlobException( 71 | 'variableValue', 'variableValue', $this->getTypeFixture(self::STRING_FIXTURE) 72 | ); 73 | } 74 | 75 | public function testMessage() 76 | { 77 | $pattern = 'pattern'; 78 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 79 | $error = new StringNotMatchGlobException('variableName', $fixture, $pattern); 80 | 81 | $this->assertSame( 82 | sprintf( 83 | 'Variable "$variableName" must match glob pattern "%s", actual value: "%s"', 84 | (string) $pattern, 85 | (string) $fixture 86 | ), 87 | $error->getMessage() 88 | ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/unit/exceptions/StringNotMatchRegExpExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidStringException; 11 | use KoKoKo\assert\exceptions\StringNotMatchRegExpException; 12 | use KoKoKo\assert\tests\BaseUnitTestCase; 13 | 14 | class StringNotMatchRegExpExceptionTest extends BaseUnitTestCase 15 | { 16 | public function testConstructWithVariableName() 17 | { 18 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 19 | 20 | foreach ($fixtures as $typeName => $typeValue) { 21 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 22 | 23 | try { 24 | new StringNotMatchRegExpException($typeValue, 1, 1); 25 | 26 | $this->fail('Not fail with: ' . $expectedMessage); 27 | } catch (InvalidStringException $error) { 28 | $this->assertSame($expectedMessage, $error->getMessage()); 29 | } 30 | } 31 | } 32 | 33 | public function testConstructWithVariableValue() 34 | { 35 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 36 | 37 | foreach ($fixtures as $typeName => $typeValue) { 38 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 39 | 40 | try { 41 | new StringNotMatchRegExpException('variableName', $typeValue, 'pattern'); 42 | 43 | $this->fail('Not fail with: ' . $expectedMessage); 44 | } catch (InvalidStringException $error) { 45 | $this->assertSame($expectedMessage, $error->getMessage()); 46 | } 47 | } 48 | 49 | new StringNotMatchRegExpException( 50 | 'variableName', $this->getTypeFixture(self::STRING_FIXTURE), 'pattern' 51 | ); 52 | } 53 | 54 | public function testConstructWithPattern() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidStringException('pattern', $typeValue))->getMessage(); 60 | 61 | try { 62 | new StringNotMatchRegExpException('variableName', 'variableValue', $typeValue); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidStringException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new StringNotMatchRegExpException( 71 | 'variableValue', 'variableValue', $this->getTypeFixture(self::STRING_FIXTURE) 72 | ); 73 | } 74 | 75 | public function testMessage() 76 | { 77 | $pattern = 'pattern'; 78 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 79 | $error = new StringNotMatchRegExpException('variableName', $fixture, $pattern); 80 | 81 | $this->assertSame( 82 | sprintf( 83 | 'Variable "$variableName" must match RegExp pattern "%s", actual value: "%s"', 84 | (string) $pattern, 85 | (string) $fixture 86 | ), 87 | $error->getMessage() 88 | ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotLessExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotLessException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotLessExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotLessException($typeValue, 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotLessException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotLessException('variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1); 51 | new NumberNotLessException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE), 1); 52 | } 53 | 54 | public function testConstructWithNumber() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidIntOrFloatException('number', $typeValue))->getMessage(); 60 | 61 | try { 62 | new NumberNotLessException('variableName', 1, $typeValue); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidIntOrFloatException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new NumberNotLessException('variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE)); 71 | new NumberNotLessException('variableValue', 1, $this->getTypeFixture(self::FLOAT_FIXTURE)); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $number = -100; 77 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 78 | $error = new NumberNotLessException('variableName', $fixture, $number); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must be less than "%s", actual value: "%s"', 83 | (string) $number, 84 | (string) $fixture 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotGreaterExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotGreaterException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotGreaterExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotGreaterException($typeValue, 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotGreaterException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotGreaterException('variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1); 51 | new NumberNotGreaterException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE), 1); 52 | } 53 | 54 | public function testConstructWithNumber() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidIntOrFloatException('number', $typeValue))->getMessage(); 60 | 61 | try { 62 | new NumberNotGreaterException('variableName', 1, $typeValue); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidIntOrFloatException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new NumberNotGreaterException('variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE)); 71 | new NumberNotGreaterException('variableValue', 1, $this->getTypeFixture(self::FLOAT_FIXTURE)); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $number = -100; 77 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 78 | $error = new NumberNotGreaterException('variableName', $fixture, $number); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must be greater than "%s", actual value: "%s"', 83 | (string) $number, 84 | (string) $fixture 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotLessStrictlyExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotLessStrictlyException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotLessStrictlyExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotLessStrictlyException($typeValue, 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotLessStrictlyException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotLessStrictlyException('variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1); 51 | new NumberNotLessStrictlyException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE), 1); 52 | } 53 | 54 | public function testConstructWithNumber() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidIntOrFloatException('number', $typeValue))->getMessage(); 60 | 61 | try { 62 | new NumberNotLessStrictlyException('variableName', 1, $typeValue); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidIntOrFloatException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new NumberNotLessStrictlyException('variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE)); 71 | new NumberNotLessStrictlyException('variableValue', 1, $this->getTypeFixture(self::FLOAT_FIXTURE)); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $number = -100; 77 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 78 | $error = new NumberNotLessStrictlyException('variableName', $fixture, $number); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must be strictly less than "%s", actual value: "%s"', 83 | (string) $number, 84 | (string) $fixture 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotGreaterStrictlyExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotGreaterStrictlyException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotGreaterStrictlyExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotGreaterStrictlyException($typeValue, 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotGreaterStrictlyException('variableName', $typeValue, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotGreaterStrictlyException('variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1); 51 | new NumberNotGreaterStrictlyException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE), 1); 52 | } 53 | 54 | public function testConstructThirdArgument() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidIntOrFloatException('number', $typeValue))->getMessage(); 60 | 61 | try { 62 | new NumberNotGreaterStrictlyException('variableName', 1, $typeValue); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidIntOrFloatException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new NumberNotGreaterStrictlyException('variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE)); 71 | new NumberNotGreaterStrictlyException('variableValue', 1, $this->getTypeFixture(self::FLOAT_FIXTURE)); 72 | } 73 | 74 | public function testMessage() 75 | { 76 | $number = -100; 77 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 78 | $error = new NumberNotGreaterStrictlyException('variableName', $fixture, $number); 79 | 80 | $this->assertSame( 81 | sprintf( 82 | 'Variable "$variableName" must be strictly greater than "%s", actual value: "%s"', 83 | (string) $number, 84 | (string) $fixture 85 | ), 86 | $error->getMessage() 87 | ); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /tests/unit/exceptions/InvalidArrayCountExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidArrayCountException; 11 | use KoKoKo\assert\exceptions\InvalidArrayException; 12 | use KoKoKo\assert\exceptions\InvalidIntException; 13 | use KoKoKo\assert\exceptions\InvalidStringException; 14 | use KoKoKo\assert\exceptions\NumberNotGreaterException; 15 | use KoKoKo\assert\tests\BaseUnitTestCase; 16 | 17 | class InvalidArrayCountExceptionTest extends BaseUnitTestCase 18 | { 19 | public function testConstructWithVariableName() 20 | { 21 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 22 | 23 | foreach ($fixtures as $typeName => $typeValue) { 24 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 25 | 26 | try { 27 | new InvalidArrayCountException($typeValue, 'variableName', 1); 28 | 29 | $this->fail('Not fail with: ' . $expectedMessage); 30 | } catch (InvalidStringException $error) { 31 | $this->assertSame($expectedMessage, $error->getMessage()); 32 | } 33 | } 34 | } 35 | 36 | public function testConstructWithVariableValue() 37 | { 38 | $fixtures = $this->getTypeFixturesWithout([self::ARRAY_FIXTURE]); 39 | 40 | foreach ($fixtures as $typeName => $typeValue) { 41 | $expectedMessage = (new InvalidArrayException('variableValue', $typeValue))->getMessage(); 42 | 43 | try { 44 | new InvalidArrayCountException('variableName', $typeValue, 1); 45 | 46 | $this->fail('Not fail with: ' . $expectedMessage); 47 | } catch (InvalidArrayException $error) { 48 | $this->assertSame($expectedMessage, $error->getMessage()); 49 | } 50 | } 51 | } 52 | 53 | public function testConstructWithCount() 54 | { 55 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 56 | 57 | foreach ($fixtures as $typeName => $typeValue) { 58 | $expectedMessage = (new InvalidIntException('count', $typeValue))->getMessage(); 59 | 60 | try { 61 | new InvalidArrayCountException('variableName', [], $typeValue); 62 | 63 | $this->fail('Not fail with: ' . $expectedMessage); 64 | } catch (InvalidIntException $error) { 65 | $this->assertSame($expectedMessage, $error->getMessage()); 66 | } 67 | } 68 | 69 | $count = -1; 70 | $expectedMessage = (new NumberNotGreaterException('count', $count, 0))->getMessage(); 71 | 72 | try { 73 | new InvalidArrayCountException('variableName', [], $count); 74 | 75 | $this->fail('Not fail with: ' . $expectedMessage); 76 | } catch (NumberNotGreaterException $error) { 77 | $this->assertSame($expectedMessage, $error->getMessage()); 78 | } 79 | } 80 | 81 | public function testMessage() 82 | { 83 | $variableName = 'variableName'; 84 | $variableValue = ['test']; 85 | $count = 2; 86 | $error = new InvalidArrayCountException($variableName, $variableValue, $count); 87 | 88 | $this->assertSame( 89 | sprintf( 90 | 'Variable "$%s" must contain: "%d" elements, actual count: "%d"', 91 | $variableName, 92 | $count, 93 | count($variableValue) 94 | ), 95 | $error->getMessage() 96 | ); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /tests/unit/exceptions/LengthNotBetweenExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\LengthNotBetweenException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class LengthNotBetweenExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new LengthNotBetweenException($typeValue, 'variableValue', 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidStringException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new LengthNotBetweenException('variableName', $typeValue, 1, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidStringException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new LengthNotBetweenException('variableValue', $this->getTypeFixture(self::STRING_FIXTURE), 1, 1); 51 | } 52 | 53 | public function testConstructWithFrom() 54 | { 55 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 56 | 57 | foreach ($fixtures as $typeName => $typeValue) { 58 | $expectedMessage = (new InvalidIntException('from', $typeValue))->getMessage(); 59 | 60 | try { 61 | new LengthNotBetweenException('variableName', 'variableValue', $typeValue, 1); 62 | 63 | $this->fail('Not fail with: ' . $expectedMessage); 64 | } catch (InvalidIntException $error) { 65 | $this->assertSame($expectedMessage, $error->getMessage()); 66 | } 67 | } 68 | 69 | new LengthNotBetweenException( 70 | 'variableName', 'variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1 71 | ); 72 | } 73 | 74 | public function testConstructFourthArgument() 75 | { 76 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE]); 77 | 78 | foreach ($fixtures as $typeName => $typeValue) { 79 | $expectedMessage = (new InvalidIntException('to', $typeValue))->getMessage(); 80 | 81 | try { 82 | new LengthNotBetweenException('variableName', 'variableValue', 1, $typeValue); 83 | 84 | $this->fail('Not fail with: ' . $expectedMessage); 85 | } catch (InvalidIntException $error) { 86 | $this->assertSame($expectedMessage, $error->getMessage()); 87 | } 88 | } 89 | 90 | new LengthNotBetweenException( 91 | 'variableName', 'variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE) 92 | ); 93 | } 94 | 95 | public function testMessage() 96 | { 97 | $from = 1; 98 | $to = 5; 99 | $fixture = $this->getTypeFixture(self::STRING_FIXTURE); 100 | $error = new LengthNotBetweenException('variableName', $fixture, $from, $to); 101 | 102 | $this->assertSame( 103 | sprintf( 104 | 'Variable "$variableName" must have length between "%s" and "%s", actual length: "%s"', 105 | (string) $from, 106 | (string) $to, 107 | mb_strlen($fixture) 108 | ), 109 | $error->getMessage() 110 | ); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotBetweenExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotBetweenException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotBetweenExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotBetweenException($typeValue, 1, 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotBetweenException('variableName', $typeValue, 1, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotBetweenException('variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1, 1); 51 | new NumberNotBetweenException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE), 1, 1); 52 | } 53 | 54 | public function testConstructWithFrom() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidIntOrFloatException('from', $typeValue))->getMessage(); 60 | 61 | try { 62 | new NumberNotBetweenException('variableName', 1, $typeValue, 1); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidIntOrFloatException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new NumberNotBetweenException('variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE), 1); 71 | new NumberNotBetweenException('variableValue', 1, $this->getTypeFixture(self::FLOAT_FIXTURE), 1); 72 | } 73 | 74 | public function testConstructWithTo() 75 | { 76 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 77 | 78 | foreach ($fixtures as $typeName => $typeValue) { 79 | $expectedMessage = (new InvalidIntOrFloatException('to', $typeValue))->getMessage(); 80 | 81 | try { 82 | new NumberNotBetweenException('variableName', 1, 1, $typeValue); 83 | 84 | $this->fail('Not fail with: ' . $expectedMessage); 85 | } catch (InvalidIntOrFloatException $error) { 86 | $this->assertSame($expectedMessage, $error->getMessage()); 87 | } 88 | } 89 | 90 | new NumberNotBetweenException('variableValue', 1, 1, $this->getTypeFixture(self::INT_FIXTURE)); 91 | new NumberNotBetweenException('variableValue', 1, 1, $this->getTypeFixture(self::FLOAT_FIXTURE)); 92 | } 93 | 94 | public function testMessage() 95 | { 96 | $from = -100; 97 | $to = 100; 98 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 99 | $error = new NumberNotBetweenException('variableName', $fixture, $from, $to); 100 | 101 | $this->assertSame( 102 | sprintf( 103 | 'Variable "$variableName" must be between "%s" and "%s", actual value: "%s"', 104 | (string) $from, 105 | (string) $to, 106 | (string) $fixture 107 | ), 108 | $error->getMessage() 109 | ); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /tests/unit/exceptions/NumberNotBetweenStrictlyExceptionTest.php: -------------------------------------------------------------------------------- 1 | 5 | * @license https://raw.github.com/ko-ko-ko/php-assert/master/LICENSE 6 | */ 7 | 8 | namespace KoKoKo\assert\tests\unit\exceptions; 9 | 10 | use KoKoKo\assert\exceptions\InvalidIntOrFloatException; 11 | use KoKoKo\assert\exceptions\InvalidStringException; 12 | use KoKoKo\assert\exceptions\NumberNotBetweenStrictlyException; 13 | use KoKoKo\assert\tests\BaseUnitTestCase; 14 | 15 | class NumberNotBetweenStrictlyExceptionTest extends BaseUnitTestCase 16 | { 17 | public function testConstructWithVariableName() 18 | { 19 | $fixtures = $this->getTypeFixturesWithout([self::STRING_FIXTURE]); 20 | 21 | foreach ($fixtures as $typeName => $typeValue) { 22 | $expectedMessage = (new InvalidStringException('variableName', $typeValue))->getMessage(); 23 | 24 | try { 25 | new NumberNotBetweenStrictlyException($typeValue, 1, 1, 1); 26 | 27 | $this->fail('Not fail with: ' . $expectedMessage); 28 | } catch (InvalidStringException $error) { 29 | $this->assertSame($expectedMessage, $error->getMessage()); 30 | } 31 | } 32 | } 33 | 34 | public function testConstructWithVariableValue() 35 | { 36 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 37 | 38 | foreach ($fixtures as $typeName => $typeValue) { 39 | $expectedMessage = (new InvalidIntOrFloatException('variableValue', $typeValue))->getMessage(); 40 | 41 | try { 42 | new NumberNotBetweenStrictlyException('variableName', $typeValue, 1, 1); 43 | 44 | $this->fail('Not fail with: ' . $expectedMessage); 45 | } catch (InvalidIntOrFloatException $error) { 46 | $this->assertSame($expectedMessage, $error->getMessage()); 47 | } 48 | } 49 | 50 | new NumberNotBetweenStrictlyException('variableValue', $this->getTypeFixture(self::INT_FIXTURE), 1, 1); 51 | new NumberNotBetweenStrictlyException('variableValue', $this->getTypeFixture(self::FLOAT_FIXTURE), 1, 1); 52 | } 53 | 54 | public function testConstructThirdArgument() 55 | { 56 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 57 | 58 | foreach ($fixtures as $typeName => $typeValue) { 59 | $expectedMessage = (new InvalidIntOrFloatException('from', $typeValue))->getMessage(); 60 | 61 | try { 62 | new NumberNotBetweenStrictlyException('variableName', 1, $typeValue, 1); 63 | 64 | $this->fail('Not fail with: ' . $expectedMessage); 65 | } catch (InvalidIntOrFloatException $error) { 66 | $this->assertSame($expectedMessage, $error->getMessage()); 67 | } 68 | } 69 | 70 | new NumberNotBetweenStrictlyException('variableValue', 1, $this->getTypeFixture(self::INT_FIXTURE), 1); 71 | new NumberNotBetweenStrictlyException('variableValue', 1, $this->getTypeFixture(self::FLOAT_FIXTURE), 1); 72 | } 73 | 74 | public function testConstructFourthArgument() 75 | { 76 | $fixtures = $this->getTypeFixturesWithout([self::INT_FIXTURE, self::FLOAT_FIXTURE]); 77 | 78 | foreach ($fixtures as $typeName => $typeValue) { 79 | $expectedMessage = (new InvalidIntOrFloatException('to', $typeValue))->getMessage(); 80 | 81 | try { 82 | new NumberNotBetweenStrictlyException('variableName', 1, 1, $typeValue); 83 | 84 | $this->fail('Not fail with: ' . $expectedMessage); 85 | } catch (InvalidIntOrFloatException $error) { 86 | $this->assertSame($expectedMessage, $error->getMessage()); 87 | } 88 | } 89 | 90 | new NumberNotBetweenStrictlyException('variableValue', 1, 1, $this->getTypeFixture(self::INT_FIXTURE)); 91 | new NumberNotBetweenStrictlyException('variableValue', 1, 1, $this->getTypeFixture(self::FLOAT_FIXTURE)); 92 | } 93 | 94 | public function testMessage() 95 | { 96 | $from = -100; 97 | $to = 100; 98 | $fixture = $this->getTypeFixture(self::INT_FIXTURE); 99 | $error = new NumberNotBetweenStrictlyException('variableName', $fixture, $from, $to); 100 | 101 | $this->assertSame( 102 | sprintf( 103 | 'Variable "$variableName" must be strictly between "%s" and "%s", actual value: "%s"', 104 | (string) $from, 105 | (string) $to, 106 | (string) $fixture 107 | ), 108 | $error->getMessage() 109 | ); 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /.provision/files/dot/.bash_git: -------------------------------------------------------------------------------- 1 | # bash/zsh git prompt support 2 | # 3 | # Copyright (C) 2006,2007 Shawn O. Pearce 4 | # Distributed under the GNU General Public License, version 2.0. 5 | # 6 | # This script allows you to see repository status in your prompt. 7 | # 8 | # To enable: 9 | # 10 | # 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh). 11 | # 2) Add the following line to your .bashrc/.zshrc: 12 | # source ~/.git-prompt.sh 13 | # 3a) Change your PS1 to call __git_ps1 as 14 | # command-substitution: 15 | # Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ ' 16 | # ZSH: setopt PROMPT_SUBST ; PS1='[%n@%m %c$(__git_ps1 " (%s)")]\$ ' 17 | # the optional argument will be used as format string. 18 | # 3b) Alternatively, for a slightly faster prompt, __git_ps1 can 19 | # be used for PROMPT_COMMAND in Bash or for precmd() in Zsh 20 | # with two parameters,
 and , which are strings
 21 | #        you would put in $PS1 before and after the status string
 22 | #        generated by the git-prompt machinery.  e.g.
 23 | #        Bash: PROMPT_COMMAND='__git_ps1 "\u@\h:\w" "\\\$ "'
 24 | #          will show username, at-sign, host, colon, cwd, then
 25 | #          various status string, followed by dollar and SP, as
 26 | #          your prompt.
 27 | #        ZSH:  precmd () { __git_ps1 "%n" ":%~$ " "|%s" }
 28 | #          will show username, pipe, then various status string,
 29 | #          followed by colon, cwd, dollar and SP, as your prompt.
 30 | #        Optionally, you can supply a third argument with a printf
 31 | #        format string to finetune the output of the branch status
 32 | #
 33 | # The repository status will be displayed only if you are currently in a
 34 | # git repository. The %s token is the placeholder for the shown status.
 35 | #
 36 | # The prompt status always includes the current branch name.
 37 | #
 38 | # In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value,
 39 | # unstaged (*) and staged (+) changes will be shown next to the branch
 40 | # name.  You can configure this per-repository with the
 41 | # bash.showDirtyState variable, which defaults to true once
 42 | # GIT_PS1_SHOWDIRTYSTATE is enabled.
 43 | #
 44 | # You can also see if currently something is stashed, by setting
 45 | # GIT_PS1_SHOWSTASHSTATE to a nonempty value. If something is stashed,
 46 | # then a '$' will be shown next to the branch name.
 47 | #
 48 | # If you would like to see if there're untracked files, then you can set
 49 | # GIT_PS1_SHOWUNTRACKEDFILES to a nonempty value. If there're untracked
 50 | # files, then a '%' will be shown next to the branch name.  You can
 51 | # configure this per-repository with the bash.showUntrackedFiles
 52 | # variable, which defaults to true once GIT_PS1_SHOWUNTRACKEDFILES is
 53 | # enabled.
 54 | #
 55 | # If you would like to see the difference between HEAD and its upstream,
 56 | # set GIT_PS1_SHOWUPSTREAM="auto".  A "<" indicates you are behind, ">"
 57 | # indicates you are ahead, "<>" indicates you have diverged and "="
 58 | # indicates that there is no difference. You can further control
 59 | # behaviour by setting GIT_PS1_SHOWUPSTREAM to a space-separated list
 60 | # of values:
 61 | #
 62 | #     verbose       show number of commits ahead/behind (+/-) upstream
 63 | #     name          if verbose, then also show the upstream abbrev name
 64 | #     legacy        don't use the '--count' option available in recent
 65 | #                   versions of git-rev-list
 66 | #     git           always compare HEAD to @{upstream}
 67 | #     svn           always compare HEAD to your SVN upstream
 68 | #
 69 | # By default, __git_ps1 will compare HEAD to your SVN upstream if it can
 70 | # find one, or @{upstream} otherwise.  Once you have set
 71 | # GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
 72 | # setting the bash.showUpstream config variable.
 73 | #
 74 | # If you would like to see more information about the identity of
 75 | # commits checked out as a detached HEAD, set GIT_PS1_DESCRIBE_STYLE
 76 | # to one of these values:
 77 | #
 78 | #     contains      relative to newer annotated tag (v1.6.3.2~35)
 79 | #     branch        relative to newer tag or branch (master~4)
 80 | #     describe      relative to older annotated tag (v1.6.3.1-13-gdd42c2f)
 81 | #     default       exactly matching tag
 82 | #
 83 | # If you would like a colored hint about the current dirty state, set
 84 | # GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
 85 | # the colored output of "git status -sb" and are available only when
 86 | # using __git_ps1 for PROMPT_COMMAND or precmd.
 87 | 
 88 | # check whether printf supports -v
 89 | __git_printf_supports_v=
 90 | printf -v __git_printf_supports_v -- '%s' yes >/dev/null 2>&1
 91 | 
 92 | # stores the divergence from upstream in $p
 93 | # used by GIT_PS1_SHOWUPSTREAM
 94 | __git_ps1_show_upstream ()
 95 | {
 96 | 	local key value
 97 | 	local svn_remote svn_url_pattern count n
 98 | 	local upstream=git legacy="" verbose="" name=""
 99 | 
100 | 	svn_remote=()
101 | 	# get some config options from git-config
102 | 	local output="$(git config -z --get-regexp '^(svn-remote\..*\.url|bash\.showupstream)$' 2>/dev/null | tr '\0\n' '\n ')"
103 | 	while read -r key value; do
104 | 		case "$key" in
105 | 		bash.showupstream)
106 | 			GIT_PS1_SHOWUPSTREAM="$value"
107 | 			if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
108 | 				p=""
109 | 				return
110 | 			fi
111 | 			;;
112 | 		svn-remote.*.url)
113 | 			svn_remote[$((${#svn_remote[@]} + 1))]="$value"
114 | 			svn_url_pattern="$svn_url_pattern\\|$value"
115 | 			upstream=svn+git # default upstream is SVN if available, else git
116 | 			;;
117 | 		esac
118 | 	done <<< "$output"
119 | 
120 | 	# parse configuration values
121 | 	for option in ${GIT_PS1_SHOWUPSTREAM}; do
122 | 		case "$option" in
123 | 		git|svn) upstream="$option" ;;
124 | 		verbose) verbose=1 ;;
125 | 		legacy)  legacy=1  ;;
126 | 		name)    name=1 ;;
127 | 		esac
128 | 	done
129 | 
130 | 	# Find our upstream
131 | 	case "$upstream" in
132 | 	git)    upstream="@{upstream}" ;;
133 | 	svn*)
134 | 		# get the upstream from the "git-svn-id: ..." in a commit message
135 | 		# (git-svn uses essentially the same procedure internally)
136 | 		local -a svn_upstream
137 | 		svn_upstream=($(git log --first-parent -1 \
138 | 					--grep="^git-svn-id: \(${svn_url_pattern#??}\)" 2>/dev/null))
139 | 		if [[ 0 -ne ${#svn_upstream[@]} ]]; then
140 | 			svn_upstream=${svn_upstream[${#svn_upstream[@]} - 2]}
141 | 			svn_upstream=${svn_upstream%@*}
142 | 			local n_stop="${#svn_remote[@]}"
143 | 			for ((n=1; n <= n_stop; n++)); do
144 | 				svn_upstream=${svn_upstream#${svn_remote[$n]}}
145 | 			done
146 | 
147 | 			if [[ -z "$svn_upstream" ]]; then
148 | 				# default branch name for checkouts with no layout:
149 | 				upstream=${GIT_SVN_ID:-git-svn}
150 | 			else
151 | 				upstream=${svn_upstream#/}
152 | 			fi
153 | 		elif [[ "svn+git" = "$upstream" ]]; then
154 | 			upstream="@{upstream}"
155 | 		fi
156 | 		;;
157 | 	esac
158 | 
159 | 	# Find how many commits we are ahead/behind our upstream
160 | 	if [[ -z "$legacy" ]]; then
161 | 		count="$(git rev-list --count --left-right \
162 | 				"$upstream"...HEAD 2>/dev/null)"
163 | 	else
164 | 		# produce equivalent output to --count for older versions of git
165 | 		local commits
166 | 		if commits="$(git rev-list --left-right "$upstream"...HEAD 2>/dev/null)"
167 | 		then
168 | 			local commit behind=0 ahead=0
169 | 			for commit in $commits
170 | 			do
171 | 				case "$commit" in
172 | 				"<"*) ((behind++)) ;;
173 | 				*)    ((ahead++))  ;;
174 | 				esac
175 | 			done
176 | 			count="$behind	$ahead"
177 | 		else
178 | 			count=""
179 | 		fi
180 | 	fi
181 | 
182 | 	# calculate the result
183 | 	if [[ -z "$verbose" ]]; then
184 | 		case "$count" in
185 | 		"") # no upstream
186 | 			p="" ;;
187 | 		"0	0") # equal to upstream
188 | 			p="=" ;;
189 | 		"0	"*) # ahead of upstream
190 | 			p=">" ;;
191 | 		*"	0") # behind upstream
192 | 			p="<" ;;
193 | 		*)	    # diverged from upstream
194 | 			p="<>" ;;
195 | 		esac
196 | 	else
197 | 		case "$count" in
198 | 		"") # no upstream
199 | 			p="" ;;
200 | 		"0	0") # equal to upstream
201 | 			p=" u=" ;;
202 | 		"0	"*) # ahead of upstream
203 | 			p=" u+${count#0	}" ;;
204 | 		*"	0") # behind upstream
205 | 			p=" u-${count%	0}" ;;
206 | 		*)	    # diverged from upstream
207 | 			p=" u+${count#*	}-${count%	*}" ;;
208 | 		esac
209 | 		if [[ -n "$count" && -n "$name" ]]; then
210 | 			__git_ps1_upstream_name=$(git rev-parse \
211 | 				--abbrev-ref "$upstream" 2>/dev/null)
212 | 			if [ $pcmode = yes ]; then
213 | 				# see the comments around the
214 | 				# __git_ps1_branch_name variable below
215 | 				p="$p \${__git_ps1_upstream_name}"
216 | 			else
217 | 				p="$p ${__git_ps1_upstream_name}"
218 | 				# not needed anymore; keep user's
219 | 				# environment clean
220 | 				unset __git_ps1_upstream_name
221 | 			fi
222 | 		fi
223 | 	fi
224 | 
225 | }
226 | 
227 | # Helper function that is meant to be called from __git_ps1.  It
228 | # injects color codes into the appropriate gitstring variables used
229 | # to build a gitstring.
230 | __git_ps1_colorize_gitstring ()
231 | {
232 | 	if [[ -n ${ZSH_VERSION-} ]]; then
233 | 		local c_red='%F{red}'
234 | 		local c_green='%F{green}'
235 | 		local c_lblue='%F{blue}'
236 | 		local c_clear='%f'
237 | 	else
238 | 		# Using \[ and \] around colors is necessary to prevent
239 | 		# issues with command line editing/browsing/completion!
240 | 		local c_red='\[\e[31m\]'
241 | 		local c_green='\[\e[32m\]'
242 | 		local c_lblue='\[\e[1;34m\]'
243 | 		local c_clear='\[\e[0m\]'
244 | 	fi
245 | 	local bad_color=$c_red
246 | 	local ok_color=$c_green
247 | 	local flags_color="$c_lblue"
248 | 
249 | 	local branch_color=""
250 | 	if [ $detached = no ]; then
251 | 		branch_color="$ok_color"
252 | 	else
253 | 		branch_color="$bad_color"
254 | 	fi
255 | 	c="$branch_color$c"
256 | 
257 | 	z="$c_clear$z"
258 | 	if [ "$w" = "*" ]; then
259 | 		w="$bad_color$w"
260 | 	fi
261 | 	if [ -n "$i" ]; then
262 | 		i="$ok_color$i"
263 | 	fi
264 | 	if [ -n "$s" ]; then
265 | 		s="$flags_color$s"
266 | 	fi
267 | 	if [ -n "$u" ]; then
268 | 		u="$bad_color$u"
269 | 	fi
270 | 	r="$c_clear$r"
271 | }
272 | 
273 | __git_eread ()
274 | {
275 | 	f="$1"
276 | 	shift
277 | 	test -r "$f" && read "$@" <"$f"
278 | }
279 | 
280 | # __git_ps1 accepts 0 or 1 arguments (i.e., format string)
281 | # when called from PS1 using command substitution
282 | # in this mode it prints text to add to bash PS1 prompt (includes branch name)
283 | #
284 | # __git_ps1 requires 2 or 3 arguments when called from PROMPT_COMMAND (pc)
285 | # in that case it _sets_ PS1. The arguments are parts of a PS1 string.
286 | # when two arguments are given, the first is prepended and the second appended
287 | # to the state string when assigned to PS1.
288 | # The optional third parameter will be used as printf format string to further
289 | # customize the output of the git-status string.
290 | # In this mode you can request colored hints using GIT_PS1_SHOWCOLORHINTS=true
291 | __git_ps1 ()
292 | {
293 | 	local pcmode=no
294 | 	local detached=no
295 | 	local ps1pc_start='\u@\h:\w '
296 | 	local ps1pc_end='\$ '
297 | 	local printf_format=' (%s)'
298 | 
299 | 	case "$#" in
300 | 		2|3)	pcmode=yes
301 | 			ps1pc_start="$1"
302 | 			ps1pc_end="$2"
303 | 			printf_format="${3:-$printf_format}"
304 | 		;;
305 | 		0|1)	printf_format="${1:-$printf_format}"
306 | 		;;
307 | 		*)	return
308 | 		;;
309 | 	esac
310 | 
311 | 	local repo_info rev_parse_exit_code
312 | 	repo_info="$(git rev-parse --git-dir --is-inside-git-dir \
313 | 		--is-bare-repository --is-inside-work-tree \
314 | 		--short HEAD 2>/dev/null)"
315 | 	rev_parse_exit_code="$?"
316 | 
317 | 	if [ -z "$repo_info" ]; then
318 | 		if [ $pcmode = yes ]; then
319 | 			#In PC mode PS1 always needs to be set
320 | 			PS1="$ps1pc_start$ps1pc_end"
321 | 		fi
322 | 		return
323 | 	fi
324 | 
325 | 	local short_sha
326 | 	if [ "$rev_parse_exit_code" = "0" ]; then
327 | 		short_sha="${repo_info##*$'\n'}"
328 | 		repo_info="${repo_info%$'\n'*}"
329 | 	fi
330 | 	local inside_worktree="${repo_info##*$'\n'}"
331 | 	repo_info="${repo_info%$'\n'*}"
332 | 	local bare_repo="${repo_info##*$'\n'}"
333 | 	repo_info="${repo_info%$'\n'*}"
334 | 	local inside_gitdir="${repo_info##*$'\n'}"
335 | 	local g="${repo_info%$'\n'*}"
336 | 
337 | 	local r=""
338 | 	local b=""
339 | 	local step=""
340 | 	local total=""
341 | 	if [ -d "$g/rebase-merge" ]; then
342 | 		__git_eread "$g/rebase-merge/head-name" b
343 | 		__git_eread "$g/rebase-merge/msgnum" step
344 | 		__git_eread "$g/rebase-merge/end" total
345 | 		if [ -f "$g/rebase-merge/interactive" ]; then
346 | 			r="|REBASE-i"
347 | 		else
348 | 			r="|REBASE-m"
349 | 		fi
350 | 	else
351 | 		if [ -d "$g/rebase-apply" ]; then
352 | 			__git_eread "$g/rebase-apply/next" step
353 | 			__git_eread "$g/rebase-apply/last" total
354 | 			if [ -f "$g/rebase-apply/rebasing" ]; then
355 | 				__git_eread "$g/rebase-apply/head-name" b
356 | 				r="|REBASE"
357 | 			elif [ -f "$g/rebase-apply/applying" ]; then
358 | 				r="|AM"
359 | 			else
360 | 				r="|AM/REBASE"
361 | 			fi
362 | 		elif [ -f "$g/MERGE_HEAD" ]; then
363 | 			r="|MERGING"
364 | 		elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
365 | 			r="|CHERRY-PICKING"
366 | 		elif [ -f "$g/REVERT_HEAD" ]; then
367 | 			r="|REVERTING"
368 | 		elif [ -f "$g/BISECT_LOG" ]; then
369 | 			r="|BISECTING"
370 | 		fi
371 | 
372 | 		if [ -n "$b" ]; then
373 | 			:
374 | 		elif [ -h "$g/HEAD" ]; then
375 | 			# symlink symbolic ref
376 | 			b="$(git symbolic-ref HEAD 2>/dev/null)"
377 | 		else
378 | 			local head=""
379 | 			if ! __git_eread "$g/HEAD" head; then
380 | 				if [ $pcmode = yes ]; then
381 | 					PS1="$ps1pc_start$ps1pc_end"
382 | 				fi
383 | 				return
384 | 			fi
385 | 			# is it a symbolic ref?
386 | 			b="${head#ref: }"
387 | 			if [ "$head" = "$b" ]; then
388 | 				detached=yes
389 | 				b="$(
390 | 				case "${GIT_PS1_DESCRIBE_STYLE-}" in
391 | 				(contains)
392 | 					git describe --contains HEAD ;;
393 | 				(branch)
394 | 					git describe --contains --all HEAD ;;
395 | 				(describe)
396 | 					git describe HEAD ;;
397 | 				(* | default)
398 | 					git describe --tags --exact-match HEAD ;;
399 | 				esac 2>/dev/null)" ||
400 | 
401 | 				b="$short_sha..."
402 | 				b="($b)"
403 | 			fi
404 | 		fi
405 | 	fi
406 | 
407 | 	if [ -n "$step" ] && [ -n "$total" ]; then
408 | 		r="$r $step/$total"
409 | 	fi
410 | 
411 | 	local w=""
412 | 	local i=""
413 | 	local s=""
414 | 	local u=""
415 | 	local c=""
416 | 	local p=""
417 | 
418 | 	if [ "true" = "$inside_gitdir" ]; then
419 | 		if [ "true" = "$bare_repo" ]; then
420 | 			c="BARE:"
421 | 		else
422 | 			b="GIT_DIR!"
423 | 		fi
424 | 	elif [ "true" = "$inside_worktree" ]; then
425 | 		if [ -n "${GIT_PS1_SHOWDIRTYSTATE-}" ] &&
426 | 		   [ "$(git config --bool bash.showDirtyState)" != "false" ]
427 | 		then
428 | 			git diff --no-ext-diff --quiet --exit-code || w="*"
429 | 			if [ -n "$short_sha" ]; then
430 | 				git diff-index --cached --quiet HEAD -- || i="+"
431 | 			else
432 | 				i="#"
433 | 			fi
434 | 		fi
435 | 		if [ -n "${GIT_PS1_SHOWSTASHSTATE-}" ] &&
436 | 		   [ -r "$g/refs/stash" ]; then
437 | 			s="$"
438 | 		fi
439 | 
440 | 		if [ -n "${GIT_PS1_SHOWUNTRACKEDFILES-}" ] &&
441 | 		   [ "$(git config --bool bash.showUntrackedFiles)" != "false" ] &&
442 | 		   git ls-files --others --exclude-standard --error-unmatch -- '*' >/dev/null 2>/dev/null
443 | 		then
444 | 			u="%${ZSH_VERSION+%}"
445 | 		fi
446 | 
447 | 		if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
448 | 			__git_ps1_show_upstream
449 | 		fi
450 | 	fi
451 | 
452 | 	local z="${GIT_PS1_STATESEPARATOR-" "}"
453 | 
454 | 	# NO color option unless in PROMPT_COMMAND mode
455 | 	if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
456 | 		__git_ps1_colorize_gitstring
457 | 	fi
458 | 
459 | 	b=${b##refs/heads/}
460 | 	if [ $pcmode = yes ]; then
461 | 		# In pcmode (and only pcmode) the contents of
462 | 		# $gitstring are subject to expansion by the shell.
463 | 		# Avoid putting the raw ref name in the prompt to
464 | 		# protect the user from arbitrary code execution via
465 | 		# specially crafted ref names (e.g., a ref named
466 | 		# '$(IFS=_;cmd=sudo_rm_-rf_/;$cmd)' would execute
467 | 		# 'sudo rm -rf /' when the prompt is drawn).  Instead,
468 | 		# put the ref name in a new global variable (in the
469 | 		# __git_ps1_* namespace to avoid colliding with the
470 | 		# user's environment) and reference that variable from
471 | 		# PS1.
472 | 		__git_ps1_branch_name=$b
473 | 		# note that the $ is escaped -- the variable will be
474 | 		# expanded later (when it's time to draw the prompt)
475 | 		b="\${__git_ps1_branch_name}"
476 | 	fi
477 | 
478 | 	local f="$w$i$s$u"
479 | 	local gitstring="$c$b${f:+$z$f}$r$p"
480 | 
481 | 	if [ $pcmode = yes ]; then
482 | 		if [ "${__git_printf_supports_v-}" != yes ]; then
483 | 			gitstring=$(printf -- "$printf_format" "$gitstring")
484 | 		else
485 | 			printf -v gitstring -- "$printf_format" "$gitstring"
486 | 		fi
487 | 		PS1="$ps1pc_start$gitstring$ps1pc_end"
488 | 	else
489 | 		printf -- "$printf_format" "$gitstring"
490 | 	fi
491 | }
492 | 


--------------------------------------------------------------------------------