Skip to content

Commit

Permalink
Fix readme errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaszdurka committed Feb 15, 2015
1 parent 7124978 commit 261523b
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ Status
Installation
------------

Mocka is registered as composer package on (packagist)[https://packagist.org/packages/tomaszdurka/mocka].
Mocka is registered as composer package on [packagist](https://packagist.org/packages/tomaszdurka/mocka).
```
"tomaszdurka/mocka": "dev-master"
```

Library usage
-----

Basic library usage
Mocking classes

```php
$parentClassName = 'Exception';
Expand All @@ -26,6 +26,14 @@ $exception1 = $class->newInstance(['exception message as constructor argument'])
$exception2 = $class->newInstanceWithoutConstructor();
```

Creating object of mocked classes

```php
$class = new ClassMock('MockedException', 'Exception');
$object = $class->newInstance('message');
$object->getMessage();
```

Mocking methods
```php
$class = new ClassMock('MockedException', 'Exception');
Expand All @@ -35,7 +43,7 @@ $class->mockMethod('getMessage');
$object = $class->newInstance('message');
$object->mockMethod('getMessage');

// It's possible to mock non-existent methods which will work once mocked
// It's possible to mock non-existent methods - they will work once mocked
$class->mockMethod('foo');

// It's also possible to mock static methods
Expand Down Expand Up @@ -98,8 +106,18 @@ class TestCase extends \PHPUnit_Framework_TestCase {
use \Mocka\MockaTrait;

public function testFoo() {
// When using mocka trait there are two shortcut methods added to create mocked objects
$countableExceptionClass = $this->mockClass('DateTime', ['Countable']);
$dateTimeObject = $this->mockObject('DateTime', '29-12-1984');
$dateTimeObject = $this->mockObject('DateTime', ['29-12-1984']);
}

public function testMockingMethod() {
$dateTimeObject = $this->mockObject('DateTime', ['29-12-1984']);
$this->assertSame('29', $dateTimeObject->format('d'));
$mockedFormatMethod = $dateTimeObject->mockMethod('format')->set('foo');
$this->assertSame(0, $mockedFormatMethod->getCallCount());
$this->assertSame('foo', $dateTimeObject->format('d'));
$this->assertSame(1, $mockedFormatMethod->getCallCount());
}

public function testMethodAssertions() {
Expand Down

0 comments on commit 261523b

Please sign in to comment.