TDD on Yii Core

I’m developping a Yii application that will try to reach 100 code coverage.

It means that i need to run all Yii core TDD.

After a quick svn checkout here : http://code.google.com/p/yii/source/browse/#svn%2Ftrunk%2Ftests

I’ve tried to run them but i’ve thrown a Fatal Error :-[


Fatal error: Call to a member function getColumnNames() on a non-object in yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php on line 410

My config :

phpunit 3.5.15

pear 1.9.4

php : 5.3.1 (i know that certain ReflectionClass method such as setAccessible() won’t work)

OsX Lion

XAMPP 1.7.3

If anyone has successfully ran Yii Core TDD and code coverage, and if your could share your solution, it should be great !

There can be a problem with running all the tests at once. Which test throws this error?

Just out of curiosity. Why do you want to unit test Yii Core while designing your application using TDD method? Maybe you could use PHPUnit’s build in mocking framework instead?

@samdark :

Yes i ran all tests at once using (i’m positionning in the test folder. The folder checkout from google project code)


phpunit --verbose .

TDD are running and displaying these lines in console




Week number for 2011/01/01 is 1Week number for 2011/01/07 is -50..........................................  63 / 435 ( 14%)

............................................................... 126 / 435 ( 28%)

...SSSSS....F.SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS................ 189 / 435 ( 43%)

....................................SSSSSSSSSSSSSSSSSSS........ 252 / 435 ( 57%)

E...

Fatal error: Call to a member function getColumnNames() on a non-object in /home/MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php on line 410

I hope it could help locating the issue.

Does Core TDD are working your side ?

I’ve update my local env, updating PHP version but error are the same.

I’ve also tried on my server–> same error :(

@sidewinder : I’m trying to run TDD on core Yii code using phpunit and built in TDD. I’m developing a complex plateform that required full coverage (including Core source code). That was one of the reason of chosing Yii (TDD included in core classes).

Core tests are OK if running these one by one. We have issues running these all at once but I’m not sure how to fix it. If you have an idea, let me know. Will be great to fix it.

Maybe I could help but if you have more informations about which TDD is breaking (when running all at once), i could check tdd code.

If TDD are working one by one and not all at once, it’s propably a setUpt/tearDown issue.

Hi all,

Additional info.

After looking into the YiiCore TDD code, i locate the file that stop phpunit (executing all TDD at once or only located file) :


phpunit --verbose ./framework/db/ar/CActiveRecordTest.php 

phpunit return these errors :


1) CActiveRecordTest::testValidation

CException: Property "CHasManyRelation.scopes" is not defined.


MYPATH/yii-1.1.8.r3324/framework/base/CComponent.php:174

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1946

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:2322

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:2303

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:372

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:387

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:62

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:255


2) CActiveRecordTest::testLazyRelation

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:258

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:127

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:329


3) CActiveRecordTest::testEagerRelation2

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1426

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:415


4) CActiveRecordTest::testEagerRelation

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1426

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:455


5) CActiveRecordTest::testLazyRecursiveRelation

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:295

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:258

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:127

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:476


6) CActiveRecordTest::testEagerRecursiveRelation

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1426

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:497


7) CActiveRecordTest::testRelationWithCondition

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1396

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:524


<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/cool.gif' class='bbc_emoticon' alt='8)' /> CActiveRecordTest::testRelationWithColumnAlias

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:399

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:50

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1410

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:552


9) CActiveRecordTest::testRelationWithNewRecord

Trying to get property of non-object


[color="#FF0000"]MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:62[/color]

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:572


10) CActiveRecordTest::testRelationWithDynamicCondition

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:583


11) CActiveRecordTest::testEagerTogetherRelation

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1426

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:595


12) CActiveRecordTest::testRelationalCount

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1543

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:642


13) CActiveRecordTest::testRelationalStat

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:399

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:50

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1410

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:657


14) CActiveRecordTest::testLazyLoadingWithConditions

Trying to get property of non-object


MYPATH/[color="#FF0000"]yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633[/color]

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:709


15) CActiveRecordTest::testDuplicateLazyLoadingBug

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:720


16) CActiveRecordTest::testTogetherWithOption

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:399

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:50

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1410

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:771


17) CActiveRecordTest::testScopes

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:393

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:286

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:304

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:51

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1410

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:855


18) CActiveRecordTest::testScopeWithRelations

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:910


19) CActiveRecordTest::testJoinWithoutSelect

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:399

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:50

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1410

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:1049


20) CActiveRecordTest::testHasManyThroughEager

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:1068


21) CActiveRecordTest::testHasManyThroughLazy

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:1278


22) CActiveRecordTest::testMergingWith

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:399

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveFinder.php:50

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1294

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1410

MYPATH/yii-1.1.8.r3324/test/framework/db/ar/CActiveRecordTest.php:1343

Then I decide to mark theses test as skipped modified setUp() method and trying to run all YiiCore TDD at once. Once again it fails.

Other issues on another file (this time it’s just an assertion that fails) :


phpunit --verbose ./framework/db/schema/CSqliteTest.php 

And returned logs :




PHPUnit 3.5.15 by Sebastian Bergmann.


....F.


Time: 0 seconds, Memory: 9.75Mb


There was 1 failure:


1) CSqliteTest::testResetSequence

Failed asserting that <string:1> matches expected <integer:5>.


[color="#FF0000"]MYPATH/yii-1.1.8.r3324/test/framework/db/schema/CSqliteTest.php:230[/color]



Then i’m continuing parsing YiiCore TDD tests and found another issue :


phpunit --verbose ./framework/web/

Logs returned :




PHPUnit 3.5.15 by Sebastian Bergmann.


SSSSSSSSSSSSSSSSS.........................E.......EE...


Time: 0 seconds, Memory: 16.75Mb


There were 3 errors:


1) CSortTest::testGetDirectionsWithDots

[color="#FF0000"]CDbException: The table "posts" for active record class "Post" cannot be found in the database.[/color]


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:2276

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:372

MYPATH/yii-1.1.8.r3324/framework/web/CSort.php:222

MYPATH/yii-1.1.8.r3324/framework/web/CSort.php:200

MYPATH/yii-1.1.8.r3324/test/framework/web/CSortTest.php:46


2) CJSONTest::testEncodeSingleAR

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1425

MYPATH/yii-1.1.8.r3324/test/framework/web/helpers/CJSONTest.php:34


3) CJSONTest::testEncodeMultipleARs

Trying to get property of non-object


MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:633

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:1441

MYPATH/yii-1.1.8.r3324/test/framework/web/helpers/CJSONTest.php:46



If you run CJSonTest.php independently, it works. I think it is due to the exception thrown by CSortTest.php


phpunit --verbose ./framework/web/CSortTest.php 

Logs are more explicits :




PHPUnit 3.5.15 by Sebastian Bergmann.


E


Time: 0 seconds, Memory: 9.25Mb


There was 1 error:


1) CSortTest::testGetDirectionsWithDots

[color="#FF0000"]include(Post.php): failed to open stream: No such file or directory[/color]

MYPATH/yii-1.1.8.r3324/framework/YiiBase.php:421

MYPATH/yii-1.1.8.r3324/framework/YiiBase.php:421

MYPATH/yii-1.1.8.r3324/framework/db/ar/CActiveRecord.php:371

MYPATH/yii-1.1.8.r3324/framework/web/CSort.php:222

MYPATH/yii-1.1.8.r3324/framework/web/CSort.php:200

MYPATH/yii-1.1.8.r3324/test/framework/web/CSortTest.php:46

I’m continuing having an issue after 57% of tested TDD. I will try to find other bad files.

I found 2 new assertion failed (after skipping test on CUrlManagerTest.php that break phpunit) :


1) CCompareValidatorTest::testValidationErrorsWithEquals

Failed asserting that <text> contains "Foo must be repeated exactly.".


MYPATH/yii-1.1.8.r3324/test/framework/validators/CCompareValidatorTest.php:34


2) CCompareValidatorTest::testOverrideCompareValue

Failed asserting that <text> contains "Foo must be repeated exactly".


MYPATH/yii-1.1.8.r3324/test/framework/validators/CCompareValidatorTest.php:236




I’ve also remove files under tests/framework/db/ar/* and file tests/framework/db/*.php (directly in this folder. I kept data and schema). I don’t know why, but with these files, running tdd all at once fail.

Hoping Yii dev team could fix these errors and allowing us to run all Yii Core TDD at once. It’s a powerfull argument of the solidity of a source code.

Fixed all the issues so now you should be able to run all tests at once.