2017 © Pedro Peláez
 

library mocks

Mocks for the XP Framework

image

xp-framework/mocks

Mocks for the XP Framework

  • Tuesday, January 9, 2018
  • by thekid
  • Repository
  • 2 Watchers
  • 0 Stars
  • 8,616 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

Mocks

Build status on GitHub XP Framework Module BSD Licence Requires PHP 7.0+ Supports PHP 8.0+ Latest Stable Version, (*1)

Mocks for the XP Framework., (*2)

Example

Here's an example implementation:, (*3)

use lang\IllegalAccessException;

interface Context {
  public function hasPermission($name);
}

class UserService {
  private $context;

  public function __construct(Context $context) {
    $this->context= $context;
  }

  public function allUsers() {
    if (!$this->context->hasPermission('rt=all,rn=users')) {
      throw new IllegalAccessException('Permission denied!');
    }

    return []; // TODO: Actually do something:)
  }
}

This is how we can mock the Context interface:, (*4)

use unittest\TestCase;

class UserServiceTest extends TestCase {

  #[@test]
  public function allUsers_works_when_hasPermission_returns_true() {
    $mocks= new MockRepository();
    $context= $mocks->createMock('Context');
    $context->hasPermission('rt=all,rn=users')->returns(true);
    $mocks->replayAll();

    $fixture= new UserService($context);
    $this->assertEquals([], $fixture->allUsers());
  }
}

Further reading

See XP RFC #0219 for a detailled introduction., (*5)

The Versions

20/09 2016
20/09 2016
02/05 2016

v6.5.2

6.5.2.0 http://xp-framework.net/

Mocks for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

23/01 2016

v6.5.1

6.5.1.0 http://xp-framework.net/

Mocks for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

20/12 2015

v6.5.0

6.5.0.0 http://xp-framework.net/

Mocks for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp

06/08 2015

v6.4.2

6.4.2.0 http://xp-framework.net/

Mocks for the XP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

module xp