From a1789ddde42033f1b05cc4929491214ee6e79383 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 17 Dec 2015 09:15:42 +0100 Subject: Update to MediaWiki 1.26.0 --- vendor/wikimedia/assert/COPYING | 21 +++ vendor/wikimedia/assert/README.md | 43 +++++ vendor/wikimedia/assert/composer.json | 24 +++ vendor/wikimedia/assert/phpunit.xml.dist | 27 +++ vendor/wikimedia/assert/src/Assert.php | 204 +++++++++++++++++++++ vendor/wikimedia/assert/src/AssertionException.php | 16 ++ vendor/wikimedia/assert/src/InvariantException.php | 18 ++ .../assert/src/ParameterAssertionException.php | 49 +++++ .../assert/src/ParameterElementTypeException.php | 43 +++++ .../assert/src/ParameterTypeException.php | 43 +++++ .../assert/src/PostconditionException.php | 18 ++ .../wikimedia/assert/src/PreconditionException.php | 17 ++ .../wikimedia/assert/tests/phpunit/AssertTest.php | 156 ++++++++++++++++ 13 files changed, 679 insertions(+) create mode 100644 vendor/wikimedia/assert/COPYING create mode 100644 vendor/wikimedia/assert/README.md create mode 100644 vendor/wikimedia/assert/composer.json create mode 100644 vendor/wikimedia/assert/phpunit.xml.dist create mode 100644 vendor/wikimedia/assert/src/Assert.php create mode 100644 vendor/wikimedia/assert/src/AssertionException.php create mode 100644 vendor/wikimedia/assert/src/InvariantException.php create mode 100644 vendor/wikimedia/assert/src/ParameterAssertionException.php create mode 100644 vendor/wikimedia/assert/src/ParameterElementTypeException.php create mode 100644 vendor/wikimedia/assert/src/ParameterTypeException.php create mode 100644 vendor/wikimedia/assert/src/PostconditionException.php create mode 100644 vendor/wikimedia/assert/src/PreconditionException.php create mode 100644 vendor/wikimedia/assert/tests/phpunit/AssertTest.php (limited to 'vendor/wikimedia/assert') diff --git a/vendor/wikimedia/assert/COPYING b/vendor/wikimedia/assert/COPYING new file mode 100644 index 00000000..56f0386f --- /dev/null +++ b/vendor/wikimedia/assert/COPYING @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Wikimedia Deutschland e.V. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/vendor/wikimedia/assert/README.md b/vendor/wikimedia/assert/README.md new file mode 100644 index 00000000..6fa9b4d2 --- /dev/null +++ b/vendor/wikimedia/assert/README.md @@ -0,0 +1,43 @@ +This package provides an alternative to PHP's `assert()` that allows for an simple and reliable way +to check preconditions and postconditions in PHP code. It was proposed [as a MediaWiki RFC](https://www.mediawiki.org/wiki/Requests_for_comment/Assert), +but is completely generic and can be used by any PHP program or library. It is published under the +MIT license, see the COPYING file. + +Usage +------- + +The Assert class provides several static methods for checking various kinds of assertions. +The most common kind is to check the type of a parameter, typically in a constructor or a +setter method: + + function setFoo( $foo ) { + Assert::parameterType( 'integer', $foo, 'foo' ); + Assert::parameter( $foo > 0, 'foo', 'must be greater than 0' ); + } + + function __construct( $bar, array $bazz ) { + Assert::parameterType( 'Me\MyApp\SomeClass', $bar ); + Assert::parameterElementType( 'int', $bazz ); + } + +Checking parameters, or other assertions such as pre- or postconditions, is not recommended for +performance critical regions of the code, since evaluating expressions and calling the assertion +functions costs time. + + +Rationale +----------- +The background of this proposal is the recurring discussions about whether PHP's `assert()` +can and should be used in MediaWiki code. Two relevant threads: +* [Using PHP's assert in MediaWiki code](http://www.gossamer-threads.com/lists/wiki/wikitech/275737) +* [Is assert() allowed?](http://www.gossamer-threads.com/lists/wiki/wikitech/378676) + +The outcome appears to be that +* assertions are generally a good way to improve code quality +* but PHP's ''assert()'' is broken by design + +Following a [suggestion by Tim Starling](http://www.gossamer-threads.com/lists/wiki/wikitech/378815#378815), +this package provides an alternative to PHP's built in `assert()`. + +[![Build Status](https://secure.travis-ci.org/wmde/Assert.svg)](https://travis-ci.org/wmde/Assert) +[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/wmde/Assert/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/wmde/Assert/?branch=master) diff --git a/vendor/wikimedia/assert/composer.json b/vendor/wikimedia/assert/composer.json new file mode 100644 index 00000000..121f7162 --- /dev/null +++ b/vendor/wikimedia/assert/composer.json @@ -0,0 +1,24 @@ +{ + "name": "wikimedia/assert", + "description": "Provides runtime assertions", + "keywords": ["PHP", "QA", "assert", "assertions", "precondition", "postcondition"], + "homepage": "https://github.com/wmde/Assert", + "license": "MIT", + "authors": [ + { + "name": "Daniel Kinzler" + } + ], + + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + + "autoload": { + "psr-4": { + "Wikimedia\\Assert\\": "src/", + "Wikimedia\\Assert\\Test\\": "tests/phpunit/" + } + } + +} diff --git a/vendor/wikimedia/assert/phpunit.xml.dist b/vendor/wikimedia/assert/phpunit.xml.dist new file mode 100644 index 00000000..49a2f87d --- /dev/null +++ b/vendor/wikimedia/assert/phpunit.xml.dist @@ -0,0 +1,27 @@ + + + + + + ./tests/phpunit + + + + + src + + + + \ No newline at end of file diff --git a/vendor/wikimedia/assert/src/Assert.php b/vendor/wikimedia/assert/src/Assert.php new file mode 100644 index 00000000..53b438a5 --- /dev/null +++ b/vendor/wikimedia/assert/src/Assert.php @@ -0,0 +1,204 @@ +parameterName = $parameterName; + } + + /** + * @return string + */ + public function getParameterName() { + return $this->parameterName; + } + +} diff --git a/vendor/wikimedia/assert/src/ParameterElementTypeException.php b/vendor/wikimedia/assert/src/ParameterElementTypeException.php new file mode 100644 index 00000000..eaaa663f --- /dev/null +++ b/vendor/wikimedia/assert/src/ParameterElementTypeException.php @@ -0,0 +1,43 @@ +elementType = $elementType; + } + + /** + * @return string + */ + public function getElementType() { + return $this->elementType; + } + +} diff --git a/vendor/wikimedia/assert/src/ParameterTypeException.php b/vendor/wikimedia/assert/src/ParameterTypeException.php new file mode 100644 index 00000000..943f6c08 --- /dev/null +++ b/vendor/wikimedia/assert/src/ParameterTypeException.php @@ -0,0 +1,43 @@ +parameterType = $parameterType; + } + + /** + * @return string + */ + public function getParameterType() { + return $this->parameterType; + } + +} diff --git a/vendor/wikimedia/assert/src/PostconditionException.php b/vendor/wikimedia/assert/src/PostconditionException.php new file mode 100644 index 00000000..a7753ef0 --- /dev/null +++ b/vendor/wikimedia/assert/src/PostconditionException.php @@ -0,0 +1,18 @@ +setExpectedException( 'Wikimedia\Assert\PreconditionException' ); + Assert::precondition( false, 'test' ); + } + + public function testParameter_pass() { + Assert::parameter( true, 'foo', 'test' ); + } + + public function testParameter_fail() { + try { + Assert::parameter( false, 'test', 'testing' ); + } catch ( ParameterAssertionException $ex ) { + $this->assertEquals( 'test', $ex->getParameterName() ); + } + } + + public function validParameterTypeProvider() { + return array( + 'simple' => array( 'string', 'hello' ), + 'class' => array( 'RuntimeException', new RuntimeException() ), + 'multi' => array( 'string|array|Closure', function() {} ), + 'null' => array( 'integer|null', null ), + 'callable' => array( 'null|callable', 'time' ), + ); + } + + /** + * @dataProvider validParameterTypeProvider + */ + public function testParameterType_pass( $type, $value ) { + Assert::parameterType( $type, $value, 'test' ); + } + + public function invalidParameterTypeProvider() { + return array( + 'simple' => array( 'string', 5 ), + 'class' => array( 'RuntimeException', new LogicException() ), + 'multi' => array( 'string|integer|Closure', array() ), + 'null' => array( 'integer|string', null ), + 'callable' => array( 'null|callable', array() ), + ); + } + + /** + * @dataProvider invalidParameterTypeProvider + */ + public function testParameterType_fail( $type, $value ) { + try { + Assert::parameterType( $type, $value, 'test' ); + $this->fail( 'Expected ParameterTypeException' ); + } catch ( ParameterTypeException $ex ) { + $this->assertEquals( $type, $ex->getParameterType() ); + $this->assertEquals( 'test', $ex->getParameterName() ); + } + } + + public function testParameterType_catch() { + try { + Assert::parameterType( 'string', 17, 'test' ); + $this->fail( 'Expected exception' ); + } catch ( AssertionException $ex ) { + // ok + } + } + + public function validParameterElementTypeProvider() { + return array( + 'empty' => array( 'string', array() ), + 'simple' => array( 'string', array( 'hello', 'world' ) ), + 'class' => array( 'RuntimeException', array( new RuntimeException() ) ), + 'multi' => array( 'string|array|Closure', array( array(), function() {} ) ), + 'null' => array( 'integer|null', array( null, 3, null ) ), + ); + } + + /** + * @dataProvider validParameterElementTypeProvider + */ + public function testParameterElementType_pass( $type, $value ) { + Assert::parameterElementType( $type, $value, 'test' ); + } + + public function invalidParameterElementTypeProvider() { + return array( + 'simple' => array( 'string', array( 'hello', 5 ) ), + 'class' => array( 'RuntimeException', array( new LogicException() ) ), + 'multi' => array( 'string|array|Closure', array( array(), function() {}, 5 ) ), + 'null' => array( 'integer|string', array( null, 3, null ) ), + ); + } + + /** + * @dataProvider invalidParameterElementTypeProvider + */ + public function testParameterElementType_fail( $type, $value ) { + try { + Assert::parameterElementType( $type, $value, 'test' ); + $this->fail( 'Expected ParameterElementTypeException' ); + } catch ( ParameterElementTypeException $ex ) { + $this->assertEquals( $type, $ex->getElementType() ); + $this->assertEquals( 'test', $ex->getParameterName() ); + } + } + + public function testParameterElementType_bad() { + $this->setExpectedException( 'Wikimedia\Assert\ParameterTypeException' ); + Assert::parameterElementType( 'string', 'foo', 'test' ); + } + + public function testInvariant_pass() { + Assert::invariant( true, 'test' ); + } + + public function testInvariant_fail() { + $this->setExpectedException( 'Wikimedia\Assert\InvariantException' ); + Assert::invariant( false, 'test' ); + } + + public function testPostcondition_pass() { + Assert::postcondition( true, 'test' ); + } + + public function testPostcondition_fail() { + $this->setExpectedException( 'Wikimedia\Assert\PostconditionException' ); + Assert::postcondition( false, 'test' ); + } + +} -- cgit v1.2.3-54-g00ecf