CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Unit Testing (Moderator: Michał Mach) »
  • Braindump why I think phpunit is actively hating me
Pages: [1]

Author Topic: Braindump why I think phpunit is actively hating me  (Read 6799 times)

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Braindump why I think phpunit is actively hating me
December 12, 2011, 05:27:00 am
Hi,

The goal is to fix all that and have a test unit framework I don't think is hostile to me and hates me personally (and even if I'm the more vocal, that's a shared feeling). I'm trying to suggest solutions, not moaning for the sake of it.

Part of the problem is that it doesn't follow the same convention than the rest of civi and feels like a parasite stuck on it. Part is that it's not finished more below.

1) what's the point of having a user password that you can configure? I don't see any reason to force me to handle manually a user password and host if the database is hardcoded

Why isn't it simply stored in the civicrm.settings.php file that you have to configure anyway? and we skip the params and that's it.

2) All the rest runs from the root of svn, why should it be different for the tests?

3) in order to run the tests, I have to grant super to an unprotected account (that I need to put the password on the cli command). Ie. I see running tests as a security vulnerability.

The only place I accept having the "root" password is on a my.cfg that is well protected on a non production server.

What is the need for SUPER? I'm sure we can skip that requirement.

4) The syntax to run a test for a single file is unfriendly (having to type manually the class when you have the file name right in front of you)

THat might be a command line habbit in linux, but I tend to switch between vi blablafile.php and php blablafile.php with all the autocomplete tab goodies and history , that works ok

being able to run it with the name of the file as a param

or (dream solution) instead of having a script wrapper (that can be kept anyway)

being able to simply from svnroot

php tests/phpunit/api/v3/PhoneTest.php

changes to implement (?):

instead of
require_once 'CiviTest/CiviUnitTestCase.php';
having
require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';

that would alter the include path and do the needed requires and init stuff if not done already


so we'd be able to to cycle between
vi api/v3/Phone.php
vi tests/phpunit/api/v3/PhoneTest.php
php tests/phpunit/api/v3/PhoneTest.php

would make me way less moaning.

In my ideal world I would be able to

$php tests/phpunit/api/v3/PhoneTest.php --no-init (that wouldn't re-init the db)
and
$php tests/phpunit/api/v3/PhoneTest.php testCreatePhone

Worthwhile investigating on my side or dead end?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Tgr

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: Drupal
  • MySQL version: 5.0
  • PHP version: 5.3
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 05:59:29 am
You should be able to run a single test with phpunit --filter testCreatePhone api_v3_PhoneTest
« Last Edit: December 12, 2011, 06:04:52 am by Tgr »

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 06:43:20 am
Thanks Tgr.

I was aware the feature exists, but I find the syntax hard to remember/type (compared to my suggested syntax)
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 07:06:23 am

1. I'm not very sure we should go down the path of hacking phpunit to use a syntax which seems easier to some :(

2. if you have set your .my.cnf, u dont need to enter your username/pass/host of DB (check the wiki docs)

3. dont know about super privilege and why its needed. If u can track that down it would be great

4. adding a shell wrapper script called: xaviersawesomewrapper.sh (or php) which does:

* cd to the scripts directory
* converts filename / shortname to what the framework expects
* adds the --filter if it detects wanting to test only one function
* any other issues that bug you

should not be too hard

lobo
lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 07:18:23 am
Quote from: Donald Lobo on December 12, 2011, 07:06:23 am

1. I'm not very sure we should go down the path of hacking phpunit to use a syntax which seems easier to some :(

was more to wrap the syntax to transform it so it's seen by phpunit as it expecting it, don't want to hack it either.

As for the syntax, might be because I don't use test the normal way? I don't run all the suite, but only the test i'm working on. Is this how your work too?


Quote from: Donald Lobo on December 12, 2011, 07:06:23 am
2. if you have set your .my.cnf, u dont need to enter your username/pass/host of DB (check the wiki docs)

ah ok, nice, but it means you run the tests with your mysql account, right? (ie. if a test contains code that drop all the databases, that will destroy more than just the test db)

Quote from: Donald Lobo on December 12, 2011, 07:06:23 am

3. dont know about super privilege and why its needed. If u can track that down it would be great

Will do.

Quote from: Donald Lobo on December 12, 2011, 07:06:23 am
4. adding a shell wrapper script called: xaviersawesomewrapper.sh (or php) which does:
* cd to the scripts directory
* converts filename / shortname to what the framework expects
* adds the --filter if it detects wanting to test only one function
* any other issues that bug you


Is there a function that converts file to class already?


X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 12:12:30 pm
So, I wrote a small batch file (yes windows) & to run the tests I type (from anywhere)

runtests Phone Get

Phone & et are optional arguments - run class PhoneTest & filter by 'Get'.

I have one more argument which affects where it is output to.

This little wrapper script is one reason I don't moan about the tests quite as much as you do (although I regularly give up on them for reasons previously aired)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 01:10:03 pm
That's nice, I like it. can you attach it here?
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Braindump why I think phpunit is actively hating me
December 12, 2011, 01:45:06 pm
Like I say - it's windows


Code: [Select]
cd c:/utils/eclipseworkspace/civicrm-trunk/tools
SET TEST=ALLTests
SET OUTPUT=> c:\temp.alltests.log
SET FILTER=
IF NOT [%1]==[] SET TEST=%1%Test
IF NOT  [%2]==[] SET FILTER=--filter %2%
IF NOT [%3]==[.] SET OUTPUT=%3

echo %TEST%
php scripts/phpunit -u test -ptest -h localhost %FILTER% api/v3/%TEST% %OUTPUT%
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Tgr

  • I’m new here
  • *
  • Posts: 2
  • Karma: 0
  • CiviCRM version: 3.4
  • CMS version: Drupal
  • MySQL version: 5.0
  • PHP version: 5.3
Re: Braindump why I think phpunit is actively hating me
December 13, 2011, 08:30:38 am
You could change the PHPUnit command line interpreter like this:

paste2.org/p/1822172

that will recognize test specifications in the format PhoneTest::testCreatePhone (which is the same format PHPUnit uses to report test results).

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Braindump why I think phpunit is actively hating me
December 13, 2011, 11:30:34 pm
Hi,

So in my quest of being able to do

php tests/phpunit/api/v3/ConstantTest.php #or any test file really

I did
1) replace
require_once 'CiviTest/CiviUnitTestCase.php';
by
require_once 'tests/phpunit/CiviTest/CiviUnitTestCase.php';
(something that IMO should be done by default, they are half a dozen folders in the include path, makes it harder to follow)

2) Modify CiviUnitTestCase so it tests if the init from tools/scripts/phpunit is done and if not do the needed
I got it working, almost, but then hit a:
Class api_v3_ConstantTest could not be found in tests/phpunit/api/v3/ConstantTest.php
which is quite not true

the problem is that it tests if the class exists before its code is parsed
Code: [Select]
if (!class_exists (example)) {
  die ("bummer Class example could not be found...");
}
class example {
}

So I will have a small
php bin/test.php  tests/phpunit/api/v3/ConstantTest.php
or php test/run.php  tests/phpunit/api/v3/ConstantTest.php


or something like that, I'll check with the sprinters I think I like quite well as well eileen's syntax and something along
php test/api3.php Constant
or
php test/api3.php Contact.get

would go a long way to make phpunit & I friends again.
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Braindump why I think phpunit is actively hating me
December 14, 2011, 04:26:05 pm
Implemented

$php tests/bin/api3.php [Entity] [Action]
and
$php tests/bin/run.php filetorun.php

http://issues.civicrm.org/jira/browse/CRM-9354
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

demeritcowboy

  • Ask me questions
  • ****
  • Posts: 570
  • Karma: 42
  • CiviCRM version: Always the latest!
  • CMS version: Drupal 6 mostly, still evaluating 7.
  • MySQL version: Mix of 5.0 / 5.1 / 5.5
  • PHP version: 5.3, usually on Windows
Re: Braindump why I think phpunit is actively hating me
December 16, 2011, 02:16:36 pm
I use the following wrapper script:

Code: [Select]
<?php
echo "All tests passed."
?>

Saves tons of time.

Eileen

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4195
  • Karma: 218
    • Fuzion
Re: Braindump why I think phpunit is actively hating me
December 16, 2011, 04:05:44 pm
:-)
Make today the day you step up to support CiviCRM and all the amazing organisations that are using it to improve our world - http://civicrm.org/contribute

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion »
  • Unit Testing (Moderator: Michał Mach) »
  • Braindump why I think phpunit is actively hating me

This forum was archived on 2017-11-26.