PHPackages                             syntaxerro/ymock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. syntaxerro/ymock

ActiveLibrary[Testing &amp; Quality](/categories/testing)

syntaxerro/ymock
================

Create PHPUnit mocks with YAML format

04PHP

Since Sep 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/syntaxerro/ymock)[ Packagist](https://packagist.org/packages/syntaxerro/ymock)[ RSS](/packages/syntaxerro-ymock/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)DependenciesVersions (1)Used By (0)

Create PHPUnit mocks with YML
=============================

[](#create-phpunit-mocks-with-yml)

---

### Installation

[](#installation)

```
composer require syntaxerro/ymock 0.1.x-dev
```

---

### Configuration

[](#configuration)

```
bad_query_database_connection:
  class: "\\PDO"
  disable_original_constructor: true
  methods:
    query: false
```

---

### Testing

[](#testing)

```
./run.sh
```

---

### Overview

[](#overview)

##### Classical method creating of mock

[](#classical-method-creating-of-mock)

```
class CartServiceTest extends \PHPUnit_Framework_TestCase
{
    // provider etc.
    public function addProductTest($product, $expectations)
    {
        $cart = new CartService(
            $this->createMockOfDatabase()
        );

        // some test and assertions
    }

    private function createMockOfDatabase()
    {
        $values = [0, 1, 2];

        $statement = $this->getMockBuilder(\PDOStatement::class)
            ->disableOriginalConstructor()
            ->getMock();
        $statement->method('fetchAll')->willReturn($values);

        $pdo = $this->getMockBuilder(\PDO::class)
            ->disableOriginalConstructor()
            ->getMock();

        $pdo->method('query')->willReturn($statement);

        return $pdo;
    }
}
```

##### Creating the same mock with the YMock

[](#creating-the-same-mock-with-the-ymock)

```
class CartServiceTest extends \PHPUnit_Framework_TestCase
{
    // provider etc.
    public function addProductTest($product, $expectations)
    {
        $ymock = new \SyntaxErro\YMock\YMock($this, './path/to/mocks.yml');
        $mocks = $ymock->getMocks();

        $cart = new CartService(
            $mocks->get('valid_query_database_connection')
        );

        // some test and assertions
    }
}
```

```
valid_query_database_connection:
  class: "\\PDO"
  disable_original_constructor: true
  methods:
    query:
      class: "\\PDOStatement"
      disable_original_constructor: true
      methods:
        fetchAll: [0, 1, 2]
```

---

##### Features

[](#features)

- Creating mocks suite per test in one YAML file
- Easy creating chains of mocks
- Configuring returned values (supported arrays, objects and simple types)

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10521497?v=4)[Marcin Łacina](/maintainers/syntaxerro)[@syntaxerro](https://github.com/syntaxerro)

### Embed Badge

![Health badge](/badges/syntaxerro-ymock/health.svg)

```
[![Health](https://phpackages.com/badges/syntaxerro-ymock/health.svg)](https://phpackages.com/packages/syntaxerro-ymock)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14228.7M340](/packages/dms-phpunit-arraysubset-asserts)[orchestra/workbench

Workbench Companion for Laravel Packages Development

8219.1M69](/packages/orchestra-workbench)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.5k2](/packages/phpbenchmark-phpbenchmark)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
