Skip to content

behat-ls on windows #4

@tvl83

Description

@tvl83

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.

Activity

tvl83

tvl83 commented on Jan 22, 2014

@tvl83
Author

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tvl83

        Issue actions

          behat-ls on windows · Issue #4 · knpuniversity/behat