The basic tests would be check the syntax correction and search missing or unused vars.
For example, the last day I created many “pull request” in dashboard module (you know what I am talking about), one of them with some mistakes. The main mistake was the use of an undeclared var. I suppose that you are checking all the code manually and it is normal merge small changes without testing it. It is impossible check ALL the code.
I think that if we use Travis CI, the develop of the platform will be more agile because the checking of the syntax and other derived problems will covered by Travis CI.
Other desirable target (when the previous topic is solved) is generate good defined cases of use to test the behaviour of the platform. I have for example, problem with the virtual feeds, see the following issue:
In the old forum, I am not the only person with this problem:
What else is required to get Travis to do a basic syntax and var check?
With regard to Virtual Feeds, I would recomend starting a new thread. Virtual feeds were added by @nchaveiro in Emoncms V9, neither I, nor @TrystanLea use them.
As you don’t have a phpunit.xml (or something like that) in your repository, there is basically nothing to run for Travis. This is the reason beacause you are getting the error in the building.
Take a look to this post:
Search string: “travis The command “phpunit” exited with 2”
I never have performed tests using “phpunit” and I can not help you a lot. I worked time ago with Travis CI and C++ tests. All unit test frameworks are similar and they are “easy” and “fast” to use.
I will investigate about the topic when I have free time.
I suspect that message is just information, rather than an error, and possibly a red-herring.
I’ve just changed the emoncms .travis.yml file to check just one file against phpunit instead of the whole repo and got a green light, passing the Travis checks.
Correct, good point. The builds are ‘passing’, it’s just a warning. As a test we could commit some PHP with invalid syntax? Can you think of a good example of invalid syntax we could use to test?
Rather than break a core file, I’ve added test.php to the repo, which has an incorrect assertion and should fail.
The incorrect assertion is $this->assertEquals(1+1,1);
If you want to correct the assertion @glyn.hudson hopefully it will then pass OK.
$this->assertEquals(1+1, 2);
Paul
Edit - yes it fails. Travis log extract added below clearly indicating what the problem is.
Ah great. Yes, that works. Build now passes after correction. So is Travis only testing test.php currently as this is the only file mentioned in .travis.yml?
script: phpunit test.php
Would it be possible to get Travis to evaluate all files in the repo for syntax errors?
I think that phpunit is very powerful for core function testing and TDD.
I have investigated a little bit and I found this:
We can try with this for syntax error checking:
before_script:
- if find . -name "*.php" ! -path "./vendor/*" -exec php -l {} 2>&1 \; | grep "syntax error, unexpected"; then exit 1; fi
In the example php lint analyzer is used. This tool analize the php files without execution (static way). This kind of analysis is useful for invalid syntax checking or detect the use of non declared vars.
There are more static analyzers of more higher level like: