Skip to content
Snippets Groups Projects
README.md 1.53 KiB
Newer Older
  • Learn to ignore specific revisions
  • Christophe Coevoet's avatar
    Christophe Coevoet committed
    # Prophecy
    
    
    jrfnl's avatar
    jrfnl committed
    [![Build Status](https://github.com/phpspec/prophecy-phpunit/actions/workflows/ci.yml/badge.svg)](https://github.com/phpspec/prophecy-phpunit/actions/workflows/ci.yml)
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    
    Prophecy PhpUnit integrates the [Prophecy](https://github.com/phpspec/prophecy) mocking
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    library with [PHPUnit](https://phpunit.de) to provide an easier mocking in your testsuite.
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    
    ## Installation
    
    ### Prerequisites
    
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    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.
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    
    ### Setup through composer
    
    ```bash
    
    composer require --dev phpspec/prophecy-phpunit
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    ```
    
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    You can read more about Composer on its [official webpage](https://getcomposer.org).
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    
    ## How to use it
    
    
    The trait ``ProphecyTrait`` provides a method ``prophesize($classOrInterface = null)`` to use Prophecy.
    
    Christophe Coevoet's avatar
    Christophe Coevoet committed
    For the usage of the Prophecy doubles, please refer to the [Prophecy documentation](https://github.com/phpspec/prophecy).
    
    
    Below is a usage example:
    
    use PHPUnit\Framework\TestCase;
    
    use Prophecy\PhpUnit\ProphecyTrait;
    
    use App\Security\Hasher;
    use App\Entity\User;
    
    class UserTest extends TestCase
    
        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());