View more context

 

theruss

@jkersu I was just dealing with this sort of thing earlier. While my problem is different, here are some pointers:

• Use the FunctionalTest::get(), FunctionalTest::post() or Director::test() methods • Your test suite should subclass FunctionalTest not SapphireTest • Depending on what you're testing, the above will return you an instance of HTTPResponse which you can run assertXX() methods over. And/OR • Try FunctionalTest::withURL('/some/url', function () { $this->assertXX('foo'); });

wmk

Where can I add an extension to SiteTree for a specific test only? It should generate some extra DB fields in augmentDatabase to simulate old data

wmk

Having a real hard time to publish a fixture. It doesn't write to DB for some reason. I only see the data written in the stage table and versions, but not Live. Any idea? I tried ->doPublish(), ->publishRecursive(), ->copyVersionToStage() and ->writeToStage(Versioned::Live). The code says it's published, but I cannot find it in the test database when I'm on a breakpoint in the test

wmk

Hmm, @robbieaverill @chillu... while I'm running a test case in SapphireTest, can I see the changes to DB ad hoc in phpmyadmin, or are they all wrapped in a transaction and therefor I cannot see them when I'm on a breakpoint?

robbieaverill

the test DB gets deleted once the test finishes running, but if you have a breakpoint in it you should be able to inspect it before that happens

wmk

I have a really hard time to see a page published in DB during a test. Somehow when I do a SQLSelect() I get all fields back, but phpmyadmin on the specific temp db doesn't show any rows in e.g. SiteTree_Live

robbieaverill

is your breakpoint in the test itself? yes - transactions would roll it back after each test has been run inside a test class

wmk

first when I "tested" the fixtures, I didn't manipulate the data inside the test, so I saw the DB generated

wmk

but trying to publish inside a test drove me nuts. Didn't see in phpmyadmin but could query again with a SQLSelect, which is still part of the transaction I guess

theruss

Random thought, but can you do the same manual checks that you're doing in phpMyAdmin, directly against the DB client? because an entirely new DB is generated on each test run, are you sure phpMyAdmin is selecting the right DB each time?

theruss

I haven't used a GUI client for more than 10 years, but don't you have to manually configure it to talk to a specific DB? Or can you simply add it into an input field via its GUI nowadays?

Scopey

The tests all run in transactions by default. This would prevent being able to gather detail with PHPMyAdmin because the data isn't actually changed for any other connection. You can choose to disable transactions while you debug though - just whack a protected $uses_transactions = false; in your test file.

Scopey

The transaction thing is just to make test runs quicker anyway - disabling it should only make your tests slower.

wmk

@Scopey thanks for verifying. Should write a blog post about that. Transactions are fine for speed, but while debugging I was just wondering why I don't see it from outside in PHPMyAdmin. Now I know why...


Show less replies
theruss

Does anyone know of a way to run a FunctionalTest such that the SUT is in the context of a specific HTTPRequest?

theruss

Something like FunctionalTest::withBaseURL() but more like FunctionalTest::withCompleteURL()

theruss

Maybe even something like Director::mockRequest() but rather Director::spyOnRequest()