PHP code example of cyruscollier / phpspec-php-mock

1. Go to this page and download the library: Download cyruscollier/phpspec-php-mock library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cyruscollier / phpspec-php-mock example snippets



    class Time
    {
        function getCurrentTime()
        {
            return time();
        }
    }


    use PhpSpec\ObjectBehavior;
    
    class TimeSpec extends ObjectBehavior
    {
        function it_is_initializable()
        {
            $this->shouldHaveType('Time');
        }
    
        function it_gets_the_current_time($functions)
        {
            $functions->time()->willReturn(123);
            $this->getCurrentTime()->shouldReturn(123);
        }
    }



    use PhpSpec\ObjectBehavior;
    
    class TimeSpec extends ObjectBehavior
    {
        function it_is_initializable()
        {
            $this->shouldHaveType('Time');
        }
    
        function it_gets_the_current_time($functions)
        {
            $functions->time()->willReturn(123);
            $functions->reveal();
            $this->shouldThrow('\Exception')->during('getCurrentTime', [123]);
        }
    }



    {
        "ruscollier/phpspec-php-mock": "dev-master"
        }
    }