-
Notifications
You must be signed in to change notification settings - Fork 645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loading project.yaml
and Fixtures
#4711
Loading project.yaml
and Fixtures
#4711
Conversation
…ture elements coming from project.yaml
Codecov Report
@@ Coverage Diff @@
## develop #4711 +/- ##
=============================================
- Coverage 31.63% 26.39% -5.24%
- Complexity 12886 12887 +1
=============================================
Files 531 531
Lines 38612 38880 +268
=============================================
- Hits 12214 10264 -1950
- Misses 26398 28616 +2218
Continue to review full report at Codecov.
|
Hey @markhuot! You should be able to utilize both fixtures and project.yaml if I'm not mistaken? Here's how I have them setup in one of my tests: tests/fixtures/data/entries.php <?php
return [
[
"sectionId" => $this->sectionIds['example'],
"typeId" => $this->typeIds['example']['example'],
"title" => "My Entry 1"
],
[
"sectionId" => $this->sectionIds['example'],
"typeId" => $this->typeIds['example']['example'],
"title" => "My Entry 2"
],
[
"sectionId" => $this->sectionIds['example'],
"typeId" => $this->typeIds['example']['example'],
"title" => "My Entry 3"
]
]; tests/unit/ExampleTest.php <?php
namespace myprojecttests;
use Codeception\Test\Unit;
use UnitTester;
use Craft;
use craft\elements\Entry;
use myprojecttests\fixtures\EntriesFixture;
class ExampleTest extends Unit
{
// Public properties
// =========================================================================
/**
* @var UnitTester
*/
protected $tester;
// Public methods
// =========================================================================
public function _fixtures(): array
{
return [
'entries' => [
'class' => EntriesFixture::class
]
];
}
// Tests
// =========================================================================
public function testTotalEntryFixtures()
{
// Confirm we have three entries
$this->assertEquals(3, Entry::find()->section(['example'])->total());
}
} You'll notice I'm using
Where |
@aaronbushnell, I'm not seeing the same thing. If you empty out your database and re-run the unit tests do you get a full install/setup for your tests? I can force it to work by updating What's your |
So I have my tests setup to purge my database and seed a new one (then it uses
Here ya go! actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
params:
- tests/.env
modules:
config:
\craft\test\Craft:
configFile: 'tests/_craft/config/test.php'
entryUrl: 'http://mysite.test/index.php'
projectConfig: {file: 'config/project.yaml'}
migrations: []
plugins: []
cleanup: true
transaction: true
dbSetup: {clean: true, setupCraft: true}
|
Hrm, I wonder why my experience is so different… I’ll try it on a fresh clone later and see what happens. Maybe my version is out of date. |
@markhuot Just to check one thing. Do you have the useProjectConfigFile option enabled in |
@markhuot any luck using a fresh clone? I'm not seeing the behavior you're describing, either. |
In my case, adding a |
I'm assuming you mean the Project Config data (i.e. Sections, Sites, email settings e.t.c.) and not just that |
@gtettelaar Correct |
tl;dr @elivz Yea this was weird behaviour. Here's a basic explanation: If you had cms/src/migrations/Install.php Lines 1019 to 1023 in 82e14b2
This executed before any fixtures were applied. If you had After this Codeception/Yii load your fixtures. In your case, this was happening without Project Config data. With for example @aaronbushnell the Project Config was loaded. All because of what Once that was done Codeception calls Lines 170 to 178 in 82e14b2
Now regardless of if |
Yes, that describes what I have been seeing perfectly. I just wasn't able to track down the root cause. Everything is working great since I added the Thank you for all your hard work on this testing framework! It's really going to improve the whole plugin ecosystem in the long run. |
Assuming #4804 resolves this, so going to go ahead and close, but feel free to re-open if you're still having issues, Mark. |
It is currently impossible to utilize the project.yaml and fixtures in a test scenario. I'm not sure if this is something you'd like to support because it's non-trivial to add, but I figured I'd open a PR with some suggestions for your consideration.
First, the motivation for this is to implement TDD (or any testing) on a front-end only build of a website within Craft. E.g., imagine a developer working entirely in the template layer and the Craft admin. They may create several sections, add fields to those sections, configure some globals, etc. Additionally they may have some "boilerplate" entries that define things like a representative blog post or the scaffolding of the homepage.
Currently, the above developer would have to save everything out as a
project.yaml
file so they could sync configuration between production and staging. But for testing they would then have to redefine the section and entry type configuration in a second place, in fixtures, because they load too late in the test setup.The attached fix moves the
project.yaml
setup out of the_before
flow and moves it deeper in to theloadFixutres
flow directly. This ensures it loads before the fixtures but not before the app is initialized.The major downside to this approach is that the current
loadFixtures
method isprivate
as defined in the Yii2 Codeception module. That means the attached won't actually work. If this seems feasible, though, I'm happy to open a PR over there for consideration of the upstream update.If this doesn't make any sense and there's a better way to do this I'm all ears, but I couldn't find anything in my reading of the docs or my perusal of the source.