Skip to content

Commit 31277da

Browse files
committed
updated
1 parent af728ae commit 31277da

File tree

3 files changed

+103
-1
lines changed

3 files changed

+103
-1
lines changed

_posts/2015-09-04-using-codeception-for-symfony-projects.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ That's why we recommend to have tests with real browser interaction. You can [le
4444
But what about unit and functional tests? As we decided we will put them into bundles. *Symfony-demo* has only *AppBundle* included, so we will create new Codeception setup in `src/AppBundle`. Take a note that we want those tests to be placed in their own namespace:
4545

4646
{% highlight bash %}
47-
php bin/codecept bootstrap --empty -c src/AppBundle --namespace AppBundle
47+
php bin/codecept bootstrap --empty src/AppBundle --namespace AppBundle
4848
{% endhighlight %}
4949

5050
We will also create `unit` and `functional` suites there:
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
layout: post
3+
title: "In Threshold of Codeception 2.2. Upcoming Features"
4+
date: 2016-03-05 01:03:50
5+
---
6+
7+
Codeception 2.2 is going to land in nearest weeks. We planned to release it much earlier, but as we are not bound to specific date, we decided to work more on improvements and include the most tasty ones in next release. In this and following blogposts we will review the most significant of upcoming features. So take a look what we prepared for you.
8+
9+
We don't plan any major breaking changes in this release. However, we will remove deprecations, as you may know we display deprecation warnings in output, so this break should be at least predictable.
10+
11+
### PHPUnit5 support
12+
13+
Yes, Codeception is finally will unlock it's dependency on PHPUnit 4.8 so you could receive the latest stable versions of PHPUnit. As you may know PHPUnit 5.x has much better support of PHP7, so anyone who develop using the latest version of PHP should use it. But wait, it's not the feature of Codeception 2.2 itself! Codeception 2.1.7 will be released with PHPUnit 5.x support as well.
14+
15+
## Test Dependencies
16+
17+
Finally `@depends` annotation works as you might expected it to. The hardest thing about dependencies is that PHPUnit does nothing to organize dependent tests in a right order:
18+
19+
> PHPUnit supports the declaration of explicit dependencies between test methods. Such dependencies do not define the order in which the test methods are to be executed but they allow the returning of an instance of the test fixture by a producer and passing it to the dependent consumers.
20+
21+
So their usage in Codeception was useless, especially if you were executing tests in random order with `shuffle: true` configuration. Some test frameworks, like minitest from Ruby run tests in shuffle by default. On the contrary PHPUnit restricts that, test with `@depends` annotation must be be executed after the test it relies on. It actually requires you to declare dependent tests in the same file and use the exact order of test execution.
22+
23+
Codeception takes the exact `@depends` annotation, reorders tests so dependent tests always will executed after the tests they rely on. This will work for Cest and Test formats both. And you can actually declare dependencies for tests in other files. Be sure, they will be taken, executed in the right order, and if a test fails its dependencies will be skipped. This is likely improve acceptance testing. If login test doesn't pass, you shouldn't even try to launch all other tests with authorization required.
24+
25+
Here is the annotation format to use to declare dependencies. It should be {fullClassName}:{testName}
26+
27+
```
28+
@depends UserCest:login
29+
@depends App\Service\UserTest:create
30+
```
31+
32+
## Params
33+
34+
This lines are written just in the same time as corresponding pull request is merged:
35+
36+
![](/images/params_screenshot.png)
37+
38+
Codeception 2.2 will allow you to use parameter in configuration files populated from environment variables, yaml configs or .env files. You can use parametrized vars in suite configs, by wrapping them in `%` placeholder, and adding one or several parameter providers using the `params` key in global config:
39+
40+
```yaml
41+
params: [env] # get prameters from environment vars
42+
```
43+
44+
You can use Symfony-style `.yml` files, Laravel-style `.env`, or `.ini` files to receive params.
45+
46+
This feature would be useful if you want to share database configuration with application and tests. This will especially be useful if you use some sort of credentials passed via environment vars. For instance, if you use cloud testing services, you can set login and password with params and get the real values from environment:
47+
48+
```yaml
49+
modules:
50+
enabled:
51+
- WebDriver:
52+
url: http://mysite.com
53+
host: %SAUCE_USER%:%SAUCE_KEY%@ondemand.saucelabs.com'
54+
port: 80
55+
browser: chrome
56+
capabilities:
57+
platform: 'Windows 10'
58+
```
59+
60+
## Conflicts
61+
62+
This is possibly a breaking feature which was announced in Codeception 2.1 but never worked the way it supposed to be. So let's talk about it once again. A friendly reminder, if you use config like this:
63+
64+
```yaml
65+
modules:
66+
enabled: [PhpBrowser, Laravel5, WebDriver]
67+
```
68+
69+
you will have problems in Codeception 2.2, if you didn't have them earlier. Basically the issue here, that those modules provide pretty the same API but different backends for test executions. So it's hard to tell from config, will this tests be executed as Laravel functional tests, as acceptance tests in real browser, or HTML-scrapper called PhpBrowser. We have lots of issues, when developers misuse those modules, trying to include everything in one config, and we can't help them besides the good advice to choose one module of one kind.
70+
71+
To avoid this confusion we introduced Conflicts API. Module can declare conflict for modules of the same API, and `ConfigurationException` will be thrown if you try to use them in group.
72+
73+
But what if you *really* need to use Laravel5 module along with, let's say, WebDriver? Don't worry, partially loaded modules won't get into conflict. The most common use case is using Laravel ORM methods to create-delete data for acceptance test. In this case you don't need to load all actions of Laravel5 module but only those related to ORM:
74+
75+
```yaml
76+
modules:
77+
enabled:
78+
- WebDriver:
79+
url: http://localhost
80+
browser: firefox
81+
- Laravel5:
82+
part: orm
83+
```
84+
85+
this way you receive `haveRecord`, `seeRecord`, `grabRecord`, `have`, `haveMultiple` methods running though Eloquent but `amOnPage`, `see`, etc will be executed through WebDriver.
86+
87+
If you were mixing WebDriver with PhpBrowser in order to use REST API inside acceptance tests, you can still have it. Don't enable PhpBrowser but set it as dependent module for REST:
88+
89+
```yaml
90+
modules:
91+
enabled:
92+
- WebDriver
93+
url: http://localhost/
94+
browser: firefox
95+
- REST
96+
url: http://localhost/api
97+
depends: PhpBrowser
98+
```
99+
100+
### ...and much more to come
101+
102+
Sure, that was not everything what is coming in 2.2! Stay tuned for new cool announcements, which will be posted soon. We will describe new modules, new test formats, and new features! Stay tuned.

images/params_screenshot.png

59.8 KB
Loading

0 commit comments

Comments
 (0)