Note that there are some explanatory texts on larger screens.

plurals
  1. POTest all subclasses on file update
    primarykey
    data
    text
    <p>I am learning unit testing with PHP and am following the TDD session on tutsplus: <a href="http://net.tutsplus.com/sessions/test-driven-php/" rel="nofollow">http://net.tutsplus.com/sessions/test-driven-php/</a></p> <p>I have set up a ruby watchr script to run the PHPUnit unit tests every time a file is modified using Susan Buck's script: <a href="https://gist.github.com/susanBuck/4335092" rel="nofollow">https://gist.github.com/susanBuck/4335092</a></p> <p>I would like to change the ruby script so that in addition to testing a file when it is updated it will test all files that inherit from it. I name my files to indicate inheritance (and to group files) as <em>Parent</em>.php, <em>Parent.Child</em>.php, and <em>Parent.Child.GrandChild</em>.php, etc so the watchr script could just search by name. I just have no idea how to do that.</p> <p>I would like to change:</p> <pre><code>watch("Classes/(.*).php") do |match| run_test %{Tests/#{match[1]}_test.php} end </code></pre> <p>to something like:</p> <pre><code>watch("Classes/(.*).php") do |match| files = get all classes that inherit from {match[1]} /\b{match[1]}\.(.*)\.php/i files.each do |file| run_test %{Tests/{file}_test.php} end end </code></pre> <p>How do I do the search for file names in the directory? Or, is there an easier/better way to accomplish this?</p> <p>Thanks</p> <p><strong>EDIT</strong></p> <p>This is what I ended up with:</p> <pre><code>watch("#{Library}/(.*/)?(.*).php") do |match| file_moded(match[1], match[2]) end def file_moded(path, file) subclasses = Dir["#{Library}/#{path}#{file}*.php"] p subclasses subclasses.each do |file| test_file = Tests + file.tap{|s| s.slice!(".php")}.tap{|s| s.slice!("#{Library}")} + TestFileEnd run_test test_file end end </code></pre> <p>Where Library, Tests, and TestFileEnd are values defined at the top of the file. It was also changed so that it will detect changes in subfolders to the application library and load the appropriate test file.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload