Skip to content

Commit

Permalink
Merge pull request #457 from alexislefebvre/2.x-remove-ExampleTests
Browse files Browse the repository at this point in the history
[2.x]: Remove ExampleTests, move them in documentation
  • Loading branch information
alexislefebvre committed Oct 19, 2018
2 parents 2247528 + d4be368 commit 95b0d00
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 102 deletions.
48 changes: 0 additions & 48 deletions ExampleTests/ExampleUnitTest.php

This file was deleted.

41 changes: 0 additions & 41 deletions ExampleTests/Fixtures/LoadUserData.php

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Documentation
* [Database test](doc/database.md)
* [Logged client](doc/logged.md)
* [Query counter](doc/query.md)
* [Examples](doc/examples.md)

To run tests in parallel:
* [Paratest](doc/paratest.md)
Expand Down
74 changes: 61 additions & 13 deletions ExampleTests/ExampleFunctionalTest.php → doc/examples.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,72 @@
Examples
========

Fixtures
--------

The bundle's internal tests show several ways to load fixtures:

- [data with fixtures dependencies](../tests/App/DataFixtures/ORM/LoadDependentUserData.php)
- [data with dependency injection](../tests/App/DataFixtures/ORM/LoadUserWithServiceData.php)
- [fixture loading with Alice](../tests/App/DataFixtures/ORM/user.yml)
- custom provider:
- [fixture to load](../tests/App/DataFixtures/ORM/user_with_custom_provider.yml)
- [custom provider](../tests/AppConfig/DataFixtures/Faker/Provider/FooProvider.php)
- [service declaration](../tests/AppConfig/config.yml)

Unit test
---------

```php
<?php

declare(strict_types=1);

/*
* This file is part of the Liip/FunctionalTestBundle
*
* (c) Lukas Kahwe Smith <smith@pooteeweet.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace Liip\FooBundle\Tests;

use Liip\FunctionalTestBundle\Controller\DefaultController;
use Liip\FunctionalTestBundle\Test\WebTestCase;

class ExampleUnitTest extends WebTestCase
{
/**
* Example using LiipFunctionalBundle the service mock builder.
*/
public function testIndexAction(): void
{
$view = $this->getServiceMockBuilder('FooView')->getMock();

$view->expects($this->once())
->method('setTemplate')
->with('FooBundle:Default:index.twig')
->will($this->returnValue(null))
;

$view->expects($this->once())
->method('handle')
->with()
->will($this->returnValue('success'))
;

$controller = new DefaultController($view);

$this->assertSame('success', $controller->indexAction());
}
}
```

Functional test
---------------

```php
<?php

declare(strict_types=1);

namespace Liip\FooBundle\Tests;

use Liip\FunctionalTestBundle\Test\WebTestCase;

/**
* @author Lukas Smith
* @author Daniel Barsotti
* @author Albert Jessurum
*/
class ExampleFunctionalTest extends WebTestCase
{
/**
Expand Down Expand Up @@ -71,3 +118,4 @@ public function testValidationErrors(): void
$this->assertValidationErrors(['data.username', 'data.email'], $client->getContainer());
}
}
```

0 comments on commit 95b0d00

Please sign in to comment.