0

I'm testing a website's dropdown menu to sort by Names.

$nameSort = array();
    $numOfNames = $this->getXpathCount("//td[@class='entry']");
    for($count = 1; $count <= $numOfNames; $count ++) {
        $get = $this->getText("xpath=(//td/a[contains(@href, '')])[$count]");
        array_push($nameSort, $get);
    }
    $test = sort($entrySort);
    $this->assertEquals($entrySort, $test);

But it says "There was 1 failure:

NameTest::testNameTab true does not match expected type "array".

1 Answer 1

5

Your problem is that sort returns a boolean and sorts the array in place.

As an example:

$arr = array(1,5,3); 
var_dump(sort($arr)); 
var_dump($arr);

That will result in this:

bool(true)
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(3)
  [2]=>
  int(5)
}

You probably want this (or something like it):

sort($nameSort);
$this->assertEquals($entrySort, $nameSort);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I don't know whats the difference between sort($nameSort) and giving it a variable, $test = sort($nameSort);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.