Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Unit Tests with Visual PHPUnit
  • Hi everyone,

    Today I'm trying unit tests and I've got some errors.

    Explanations : I dowloaded Visual PHPUnit, put it on SVN in order to use it in team. I tried a little test which perfectly succeded. 

    Now I'm doing something a little bit harder : I'm testing a function in a model class. This model class use Config files. We tried this syntax :

    Config::load('filename');

    in order to use it like this :

    $value = Config::get('namefile.value');

    But an error occured when triing to test the class.

    Here is the error :

    Fatal error: Class 'Config' not found in thepath on line 58 

    That's really strange because I noticed the Config class in FuelPHP documentation, so, that means that Config class is already in FuelPHP...

    Strange error, to me, need some help. Thanks.
  • If you're using PHPunit stand-alone, the rest of the framework, including the autoloader, isn't loaded, which could explain why it doesn't work.

    You run tests using 'php oil test', which sets everything up before calling PHPunit.

    I don't know how to do this with Visual PHPUnit, I've never heard of that before.
  • Hmmm...
    With Visual PHPUnit you don't have to use terminal, so, you don't have to launch your test manualy.

    You just have to select your test launcher which you have created and then click on "Run tests". But I think you are true, you can just run the library you specified. Maybe I have also to specify Config path.

    I'm gonna try it.
  • Well, somewhere in that code it starts PHPunit.

    You might be ok when you can convince it to use our phpunit.xml, which is in fuel/core, and which contains the bootstrap needed to initialize PHPunit for FuelPHP.

    Or if it requires it's own xml, make sure you configure it like ours.
  • Just checked the config of VPU.

    It allows you to specify the phpunit.xml to load, and it also allows you to define additional bootstrap scripts.

    So you should be able to construct a config that works from both from our versions in fuel/core.
  • I decided to stop Unit Testing with Visual PHPUnit.
    But now that I'm doing it with command lines I've got a new problem : I tried to use bootstrap_phpunit.php from Fuel/Core as my bootstrap to use but there is a problem : APPPATH, PKGPATH, COREPATH and DOCROOT are wrong in this file. And I've no idea what Path I have to set in each of these variables.

    Thanks for a help.
  • if you're using the commandline, you should use oil to run your tests. Everything is setup for that.

    The bootstrap gets it's data from the xml file:

        <php>
            <server name="doc_root" value="../../"/>
            <server name="app_path" value="fuel/app"/>
            <server name="core_path" value="fuel/core"/>
            <server name="package_path" value="fuel/packages"/>
            <server name="FUEL_ENV" value="test"/>
        </php>

    which are paths relative to the installation root (where the oil front controller is).
  • Yes but it seems that oil doesn't work on Windows.
  • Why not? Never had any complaints about that. Any errors?
  • For what it is worth I managed to get VisualPHPUnit working with FuelPHP. 
  • Care to share how you did it? Perhaps add it to the documentation, or write a blog post about it?

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion