Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

behat-ls on windows #4

Open
tvl83 opened this issue Jan 22, 2014 · 1 comment
Open

behat-ls on windows #4

tvl83 opened this issue Jan 22, 2014 · 1 comment

Comments

@tvl83
Copy link

tvl83 commented Jan 22, 2014

First of all, there isn't a ls command in windows, obviously. So I used dir which is roughly the equivalent (I like ls better).

I am in the FeatureContext.php file and did a var_dump($this->output) and this is what I get

array(11) {
  [0] =>
  string(32) " Volume in drive C has no label."
  [1] =>
  string(34) " Volume Serial Number is 1094-4CD1"
  [2] =>
  string(0) ""
  [3] =>
  string(78) " Directory of C:\Users\Thomas\PhpstormProjects\symfony\behat-ls\test\test\test"
  [4] =>
  string(0) ""
  [5] =>
  string(40) "01/21/2014  07:56 PM    <DIR>          ."
  [6] =>
  string(41) "01/21/2014  07:56 PM    <DIR>          .."
  [7] =>
  string(46) "01/21/2014  07:56 PM                 0 hammond"
  [8] =>
  string(43) "01/21/2014  07:56 PM                 0 john"
  [9] =>
  string(45) "               2 File(s)              0 bytes"
  [10] =>
  string(50) "               2 Dir(s)   3,029,737,472 bytes free"
}

so the array_search($string, $this->output) fails.

What can I use to make this pass, if anything?

On a side note: also because I am on windows the system('rm -r '.realpath('test')); doesn't work for me so I figured out that system('rd /S /Q '.realpath('test')); is what needs to be used.

@tvl83
Copy link
Author

tvl83 commented Jan 22, 2014

After a little more digging I figured out how to get behat-ls to work. But for windows it's more accurately called behat-dir

instead of the array_search() we are going to do loop over the $this->output with a foreach if it is found in there we flip a bool and if the bool isn't flipped at the end of the loop then we throw the exception.

$found=false;

        foreach($this->output as $line)
        {
            if(strpos($line, $string) !== false)
                $found = true;
        }

        if(!$found)
            throw new  \Exception(sprintf('Did not see "%s" in the output', $string));

Oh yea, set the $output as an array using annotation up top.

     /**
     * @var array
     */
     private $output;

This let's us iterate over the $output variable with foreach. (I don't know if this is absolutely necessary but my IDE (PHPStorm) was yelling at me about it. My scenario is passing now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant