0

I'm currently using BC Math extension in a project.

In my unit tests there are some comparisons that would be similar to the below:

This will pass:

        $this->assertEquals('1.23456789123456789123434', 
                            '1.2345678912345678912343434654654654654'
        ); 

This will not pass:

         $this->assertEquals('1.23456789123456789123434', 
                             '1.23456789123456719123434'
         ); 

I've read a few bits that seem to suggest two string will be treated as numeric if is_numeric returns true. Is there already functionality in phpunit to compare two numeric string as strings. I know I can write a custom assertion but don't want to if the functionality exists already?

I have looked pretty hard and don't seem to be able to be able to see the functionality but feel it must exist...

Purple Hexagon
  • 3,538
  • 2
  • 24
  • 45

1 Answers1

0

Ok straight after posting I work out the answer...

You can use $this->assertSame() like ...

this will pass:

    $this->assertSame('1.2345678912345678912343434654654654654',
                      '1.2345678912345678912343434654654654654'
    );

this will not pass:

    $this->assertSame('1.234567891234567891234343465465465465',
                      '1.2345678912345678912343434654654654654'
    );
Purple Hexagon
  • 3,538
  • 2
  • 24
  • 45
  • Why does the second not pass? – thelastshadow May 21 '18 at 19:43
  • Well I don't really remember much about this as it was 4 years ago but ... the example seems pretty bad. The issue was that assertions with more precision would be treated the same by assertEquals but assertSame fixed this. The second example has an extra digit that mean it should not pass. – Purple Hexagon May 22 '18 at 10:35