1

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 :)

php code php code in org src block

  • (defun org-babel-execute:phpunit (body params) "Orgmode Babel PHP evaluate function for BODY' with PARAMS'." (let* ((cmd "phpunit EmailTest.php") (body (concat "<?php\n" body "\n?>"))) (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 2 at 17:33
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.