clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# 2.3.0
* Add more precise type for the `prophesize` method
# 2.2.0
* Add support for PHPUnit 11
# 2.1.0 / 2023-12-08
Add support for PHPUnit 10.1+ (10.0 is not supported)
Bump requirement to Prophecy 1.18+
# 2.0.2 / 2023-04-18
Add the `@not-deprecated` annotation to avoid phpstan reporting `prophesize` as deprecated due to the TestCase deprecation.
# 2.0.1 / 2020-07-09
Add support for PHP 8
# 2.0.0 / 2020-04-07
Rewrite of the library for PHPUnit 9.1+, with a new API based on a trait rather than a base class.
1.1.0 / 2015-02-09
==================
* Remove the requirement to call the parent ``setUp`` method
* Add the assertion count for predictions to be compatible with PHPUnit strict mode
1.0.1 / 2014-03-04
==================
* Marked the ``ProphecyTestCase`` as abstract to avoid PhpUnit to try running it
1.0.0 / 2013-07-04
==================
* Initial release

22
vendor/phpspec/prophecy-phpunit/LICENSE vendored Normal file
View File

@@ -0,0 +1,22 @@
Copyright (c) 2013 Christophe Coevoet <stof@notk.org>
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.

View File

@@ -0,0 +1,56 @@
# Prophecy
[![Build Status](https://github.com/phpspec/prophecy-phpunit/actions/workflows/ci.yml/badge.svg)](https://github.com/phpspec/prophecy-phpunit/actions/workflows/ci.yml)
Prophecy PhpUnit integrates the [Prophecy](https://github.com/phpspec/prophecy) mocking
library with [PHPUnit](https://phpunit.de) to provide an easier mocking in your testsuite.
## Installation
### Prerequisites
Prophecy PhpUnit requires PHP 7.3 or greater.
Prophecy PhpUnit requires PHPUnit 9.1 or greater. Older versions of PHPUnit are providing the Prophecy integration themselves.
### Setup through composer
```bash
composer require --dev phpspec/prophecy-phpunit
```
You can read more about Composer on its [official webpage](https://getcomposer.org).
## How to use it
The trait ``ProphecyTrait`` provides a method ``prophesize($classOrInterface = null)`` to use Prophecy.
For the usage of the Prophecy doubles, please refer to the [Prophecy documentation](https://github.com/phpspec/prophecy).
Below is a usage example:
```php
<?php
namespace App;
use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use App\Security\Hasher;
use App\Entity\User;
class UserTest extends TestCase
{
use ProphecyTrait;
public function testPasswordHashing()
{
$hasher = $this->prophesize(Hasher::class);
$user = new User($hasher->reveal());
$hasher->generateHash($user, 'qwerty')->willReturn('hashed_pass');
$user->setPassword('qwerty');
$this->assertEquals('hashed_pass', $user->getPassword());
}
}
```

View File

@@ -0,0 +1,39 @@
{
"name": "phpspec/prophecy-phpunit",
"description": "Integrating the Prophecy mocking library in PHPUnit test cases",
"keywords": ["Phpunit", "Prophecy"],
"homepage": "http://phpspec.net",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Christophe Coevoet",
"email": "stof@notk.org"
}
],
"require": {
"php": "^7.3 || ^8",
"phpspec/prophecy": "^1.18",
"phpunit/phpunit":"^9.1 || ^10.1 || ^11.0"
},
"autoload": {
"psr-4": {
"Prophecy\\PhpUnit\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Prophecy\\PhpUnit\\Tests\\Fixtures\\": "fixtures",
"Prophecy\\PhpUnit\\Tests\\PhpstanFixtures\\": "phpstan-fixtures",
"Prophecy\\PhpUnit\\Tests\\": "tests"
}
},
"extra": {
"branch-alias": {
"dev-master": "2.x-dev"
}
},
"require-dev": {
"phpstan/phpstan": "^1.10"
}
}

View File

@@ -0,0 +1,126 @@
<?php declare(strict_types=1);
namespace Prophecy\PhpUnit;
use PHPUnit\Framework\AssertionFailedError;
use PHPUnit\Framework\Attributes\After;
use PHPUnit\Framework\Attributes\PostCondition;
use PHPUnit\Framework\TestCase;
use Prophecy\Exception\Doubler\DoubleException;
use Prophecy\Exception\Doubler\InterfaceNotFoundException;
use Prophecy\Exception\Prediction\PredictionException;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Prophecy\Prophet;
/**
* @mixin TestCase
*/
trait ProphecyTrait
{
/**
* @var Prophet|null
*
* @internal
*/
private $prophet;
/**
* @var bool
*
* @internal
*/
private $prophecyAssertionsCounted = false;
/**
* @throws DoubleException
* @throws InterfaceNotFoundException
*
* @template T of object
* @phpstan-param class-string<T>|null $classOrInterface
* @phpstan-return ($classOrInterface is null ? ObjectProphecy<object> : ObjectProphecy<T>)
*
* @not-deprecated
*/
protected function prophesize(?string $classOrInterface = null): ObjectProphecy
{
static $isPhpUnit9;
$isPhpUnit9 = $isPhpUnit9 ?? method_exists($this, 'recordDoubledType');
if (! $isPhpUnit9) {
// PHPUnit 10.1
$this->registerFailureType(PredictionException::class);
} elseif (\is_string($classOrInterface)) {
// PHPUnit 9
\assert($this instanceof TestCase);
$this->recordDoubledType($classOrInterface);
}
return $this->getProphet()->prophesize($classOrInterface);
}
/**
* @postCondition
*/
#[PostCondition]
protected function verifyProphecyDoubles(): void
{
if ($this->prophet === null) {
return;
}
try {
$this->prophet->checkPredictions();
} catch (PredictionException $e) {
throw new AssertionFailedError($e->getMessage());
} finally {
$this->countProphecyAssertions();
}
}
/**
* @after
*/
#[After]
protected function tearDownProphecy(): void
{
if (null !== $this->prophet && !$this->prophecyAssertionsCounted) {
// Some Prophecy assertions may have been done in tests themselves even when a failure happened before checking mock objects.
$this->countProphecyAssertions();
}
$this->prophet = null;
}
/**
* @internal
*/
private function countProphecyAssertions(): void
{
\assert($this instanceof TestCase);
\assert($this->prophet !== null);
$this->prophecyAssertionsCounted = true;
foreach ($this->prophet->getProphecies() as $objectProphecy) {
foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) {
foreach ($methodProphecies as $methodProphecy) {
\assert($methodProphecy instanceof MethodProphecy);
$this->addToAssertionCount(\count($methodProphecy->getCheckedPredictions()));
}
}
}
}
/**
* @internal
*/
private function getProphet(): Prophet
{
if ($this->prophet === null) {
$this->prophet = new Prophet;
}
return $this->prophet;
}
}