Comments (8)
Ok, I don't know why I have to load the FixtureManager myself, but this is how it works, when I add it to the top line of setUp()
:
$this->fixtureManager = new FixtureManager();
$this->fixtureManager->fixturize($this);
$this->loadFixtures('MyFixture');
from codeception.
@jadb Do you know if that is the right way to do it?
from codeception.
ATM, the only way is by adding it to your custom App\TestSuite\Codeception\AcceptanceHelper
(or any other). I will try seeing if it can be included by default without raising errors (or act as a listener like with PHPUnit).
<?php
namespace App\TestSuite\Codeception;
use App\TestSuite\Codeception\Helper\MailerTrait;
use App\TestSuite\FixtureTrait;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\Fixture\FixtureManager;
use Codeception\Module;
use Codeception\TestCase;
class AcceptanceHelper extends Module
{
use MailerTrait;
public $fixtures = ['app.users', 'app.posts'];
/**
* Load fixtures before scenario is run.
*
* @param TestCase $test Test case.
* @return void
*/
public function _before(TestCase $test)
{
$fixtureManager = new FixtureManager();
$test->fixtures = $this->fixtures;
$fixtureManager->fixturize($test);
$fixtureManager->load($test);
}
/**
* Drop tables after scenario is run.
*
* @param TestCase $test Test case.
* @return void
*/
public function _after(TestCase $test)
{
$connection = ConnectionManager::get('default');
foreach ($this->fixtures as $fixture) {
$parts = explode('.', $fixture);
$connection->execute('DROP TABLE ' . array_pop($parts));
}
}
}
from codeception.
@jadb But what exactly does the Framwork::_before() function? Because there you create a FixtureManager and load fixtures from TestCases...
from codeception.
Ok, I've found the trick. The Test Class must extend Codeception\TestCase\Test. My Class extended Cake\TestSuite\TestCase.
So far I can see it, it works this way. One hint: I'm always talking about the Unit Testing at the moment. I see that you always focus on Acceptance Testing (in documentation and in discussions). But the Unit Testing is far more important (for me). I want to use codeception for the acceptance and functional testing as additional feature, but the most reliable feature is the unit testing.
from codeception.
You can continue writing the unit tests in phpunit or using codeception. Maybe I missed what you were trying to communicate?
from codeception.
When I want to use cakephp/codeception I'm replacing the old testing mechanism with this one. So I'm assuming that everything the cakephp unit testing provides on functionality also works with cakephp/codeception. Just with acceptance and functional testing on top.
So when fixtures in unit testing don't work the way they worked in the classic cake unit testing, it's bad. Also the original assertions have to work.
When people switch to this plugin their old unit tests have to work or they need an instruction what they have to change to make them work.
from codeception.
I hear you and understand better now. You are right.
from codeception.
Related Issues (18)
- Update README - customizeCodeceptionBinary part of skeleton app Installer
- Shift sample_app to other branch because of multiple definition of namespaces HOT 1
- App does'nt use test DB in functional testing HOT 1
- Installation of vendor/bin/codecept goes wrong HOT 6
- Can't set http headers HOT 1
- Error Constant already defined HOT 3
- Cakephp 2.x HOT 1
- Wrong codeception composer dependency
- Compatibility problem with symfony/browser-kit v2.8.7
- Can't install with composer HOT 3
- Is there a Cake 2.x option? HOT 1
- Bootstrap created unexpected folder structure HOT 10
- Updating to codeception 2.3 HOT 2
- Broken with cakephp 3.6 HOT 5
- Fatal Error undefined function loadPHPUnitAliases() HOT 1
- Codeception Tests take 'default' datasource instead of 'test'
- Documentation - how to prepare database HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from codeception.