I'm using phpunit package https://github.com/nlamirault/phpunit.el and it works great with php files. But I have a simple php blog about refactoring ex: http://phprefactor.com/refactorings/decompose-conditional and I would like to run phpunit test in org-mode src block. That would be extremely usefull in blogging about php :)
Asked
Active
Viewed 299 times
1
-
`(defun org-babel-execute:phpunit (body params) "Orgmode Babel PHP evaluate function for `BODY' with `PARAMS'." (let* ((cmd "phpunit EmailTest.php") (body (concat ""))) (org-babel-eval cmd body) ))` I find out that this works when I set precise file, But how can it be done to run the code in #+BEGIN_SRC ? Because when i try it gives "Code block produced no output." – slk500 Feb 02 '19 at 17:33
1 Answers
1
Finally I make it work. The main problem is that org-mode shell source blocks do not capture stderr. You can read more about this here. So normally you will not see output if one of the test fails. Solution for this is to save code block to temporary file and then running org-babel-sh-command on the file which in case of failure redirect stderr to stdout. I create new config for phpunit:
(defun org-babel-execute:phpunit (body params)
"Orgmode Babel PHP evaluate function for `BODY' with `PARAMS'."
(let* ((cmd "./phpunithack.sh")
(body (concat "<?php\n" body "\n?>")))
(write-region body nil "/home/slk500/.emacs.d/EmailTest.php")
(org-babel-eval cmd body)
))
and my script phpunithack.sh looks like this:
exec 2>&1
phpunit EmailTest.php
:
Example src block:
#+BEGIN_SRC phpunit
use PHPUnit\Framework\TestCase;
class EmailTest extends TestCase
{
public function testOne(): void
{
$this->assertTrue(true);
}
public function testTwo(): void
{
$this->assertTrue(false);
}
}
#+END_SRC