PHPackages                             mockfromyaml/mockfromyaml - 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. mockfromyaml/mockfromyaml

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

mockfromyaml/mockfromyaml
=========================

PHP traits to mock objects from arrays and read the data provider arrays from yaml files.

v3.0.0(1y ago)011BSD-3-ClausePHP

Since Mar 5Pushed 1y agoCompare

[ Source](https://github.com/mcn-fredw/mock-from-yaml-php)[ Packagist](https://packagist.org/packages/mockfromyaml/mockfromyaml)[ RSS](/packages/mockfromyaml-mockfromyaml/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (2)Versions (11)Used By (1)

MockFromYaml
============

[](#mockfromyaml)

PHP traits to mock objects from arrays and read the data provider arrays from yaml files.

Installation
------------

[](#installation)

composer install (WIP)

Depends on:

phpunit/phpunit symfony/yaml

Usage
-----

[](#usage)

Using YAML files for simple test case data (don't really need this lib for that):

```
namespace Tests\libs\MyClassTest_NS;

use PHPUnit_Framework_TestCase as TestCase;
use MockFromYaml\YamlTestCasesReaderTrait;

class MyClassTest extends TestCase
{
    use YamlTestCasesReaderTrait;

    public function someMethodProvider()
    {
        return static::readYamlTestCases(__DIR__ . '/MyClassTest.someMethodProvider.yml');
    }

    /**
     * @dataProvider someMethodProvider
     */
    public function testSomeMethod($exception, $in, $expect)
    {
        if (0 < strlen($exception)) {
            $this->expectException($exception);
        }
        $obj = new MyClass();
        $this->assertEquals($expect, $obj->someMethod($in));
    }
}

```

\_\_DIR\_\_ . '/MyClassTest.someMethodProvider.yml'

```
test case 1:
    exception: null
    in: 0
    expect: false
test case 2:
    exception: null
    in: 1
    expect: true

```

Using YAML files for object mocking (high level usage):

```
namespace Tests\libs\MyClassTest_NS;

use PHPUnit_Framework_TestCase as TestCase;
use MockFromYaml\MockFromArrayCreatorTrait;
use MockFromYaml\YamlTestCasesReaderTrait;

class MyClassTest extends TestCase
{
    use YamlTestCasesReaderTrait;

    public function someMethodProvider()
    {
        return static::readYamlTestCases(__DIR__ . '/MyClassTest.someMethodProvider.yml');
    }

    /**
     * @dataProvider someMethodProvider
     */
    public function testSomeMethod($exception, $expect, $fixtures)
    {
         $domain = [ 'someIntitalValueKey' => 'someIntitalValue' ];
         $this->createMockFixtures($fixtures, $domain);
         if (0 < strlen($exception)) {
             $this->expectException($exception);
         }
        $obj = new MyClass($domain['serviceConnector']);
        $this->assertEquals($expected, $obj->someMethod($domain['authBridge']));
    }
}

```

\_\_DIR\_\_ . '/MyClassTest.someMethodProvider.yml'

```
test case 1:
    exception: null
    expect: false
    fixtures:
        # service provider mock-up
        - class: 'Project\libs\ServiceProvider'
          domain: 'serviceProvider'
          fixture:
            authenticate:
                expects: [once]
                with: [[equalTo, 'user'], [equalTo, 'token']]
                will: [returnValue, false]
        # injected -mock-dependency
        - class: 'Project\libs\ServiceConnector'
          domain: 'serviceConnector'
          fixture:
            connect:
                expects: [once]
                with: [equalTo, 'http://my.local']
                # reference service provider mock-up
                will: [returnValue, '$serviceProvider']
        # auth bridge
        - class: 'Project\libs\AuthBridge'
          domain: 'authBridge'
          fixture:
            getEntity:
                expects: [once]
                will: [returnValue, 'user']
            getToken:
                expects: [once]
                will: [returnValue, 'token']

```

Contributing
------------

[](#contributing)

1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D

History
-------

[](#history)

Initial version 1.0.0

License
-------

[](#license)

BSD 3-Clause License

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity69

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~339 days

Recently: every ~371 days

Total

9

Last Release

640d ago

Major Versions

1.0.1 → v2.0.02018-06-02

v2.0.5 → v3.0.02024-08-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/c4bf380c34cacafd67f25136d37c062a7337a1d95f2762d459022740c0b0c7a3?d=identicon)[mcn-fredw](/maintainers/mcn-fredw)

---

Top Contributors

[![mcn-fredw](https://avatars.githubusercontent.com/u/5177890?v=4)](https://github.com/mcn-fredw "mcn-fredw (28 commits)")

---

Tags

mockingphpunittraityaml-files

### Embed Badge

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

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

###  Alternatives

[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.0k](/packages/orchestra-testbench)[codeception/codeception

All-in-one PHP Testing Framework

4.9k86.2M2.9k](/packages/codeception-codeception)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M1.9k](/packages/behat-behat)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)[lastzero/test-tools

Increases testing productivity by adding a service container and self-initializing fakes to PHPUnit

2244.3k13](/packages/lastzero-test-tools)

PHPackages © 2026

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