Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sima-land/yii2-logstock

Yii2 + codeception snapshot testing extension
https://github.com/sima-land/yii2-logstock

ci codeception snapshot testing trace yii2

Last synced: 3 months ago
JSON representation

Yii2 + codeception snapshot testing extension

Awesome Lists containing this project

README

        

Snapshot testing extension for Yii 2
===========================

This extension provides recording and asserting application trace (snapshot). Based on yii\debug module.

![Cover](doc/images/terminal.png)

Support
-------
1. Unit
2. Functional (without web server) - does not support
3. Acceptance (throughout web server)

[![Latest Stable Version](https://poser.pugx.org/pastuhov/yii2-logstock/v/stable)](https://packagist.org/packages/pastuhov/yii2-logstock)
[![Build Status](https://travis-ci.org/pastuhov/yii2-logstock.svg)](https://travis-ci.org/pastuhov/yii2-logstock)
[![Total Downloads](https://poser.pugx.org/pastuhov/yii2-logstock/downloads)](https://packagist.org/packages/pastuhov/yii2-logstock)

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

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist pastuhov/yii2-logstock
```

or add

```
"require-dev": {
"pastuhov/yii2-logstock": "~1.0.0"
...
```

to the require section of your `composer.json` file.

Usage
-----

Once the extension is installed, simply modify your application configuration as follows:

```php
...
if (YII_ENV_TEST) {
// configuration adjustments for 'test' environment
$config['bootstrap'][] = 'logstock';
$config['modules']['logstock'] = [
'class' => \pastuhov\logstock\Module::class,
];

}
...
```

Add `pastuhov\logstock\UnitHelper` to suit config

```yml
modules:
enabled:
- pastuhov\logstock\UnitHelper
```

Use assertLog() method in tests
```php
...
public function testExampleUnitUsage()
{
$this->tester->assertLog(function (){
Yii::info('Test info message');
Yii::$app->getDb()->createCommand('SELECT * FROM page')->execute();
}, Yii::$app);
}
...
```

First time snapshot artifact will be recorded

```
1) Test example unit usage (unit\ExampleUnitTest::testExampleUnitUsage)
Fixture has aggregated. Please restart test!
```

Recorded snapshot:
```
Entry: console

Test info message

SELECT * FROM page
```
On subsequent test runs Logstock will simply compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code that should be fixed, or the implementation has changed and the snapshot needs to be updated.

For more info see tests.

Testing
-------

```bash
./vendor/bin/codecept run unit,acceptance
```

If web server needed:

```bash
./tests/bin/yii serve&
```

Security
--------

If you discover any security related issues, please email [email protected] instead of using the issue tracker.