55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\EldoradoRobuxPriceSentryJob;
|
||
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Illuminate\Foundation\Testing\WithFaker;
|
||
use App\Browser\Jobs\EldoradoRobuxPriceSentry\EldoradoRobuxPriceSentryJob;
|
||
use ReflectionMethod;
|
||
use Tests\TestCase;
|
||
|
||
class textToFLoatTest extends TestCase
|
||
{
|
||
private EldoradoRobuxPriceSentryJob $job;
|
||
|
||
protected function setUp(): void {
|
||
parent::setUp();
|
||
$this->job = new EldoradoRobuxPriceSentryJob();
|
||
}
|
||
|
||
private function assertTextToFloat($input, $expected) {
|
||
$reflection = new ReflectionMethod(EldoradoRobuxPriceSentryJob::class, 'textToFloat');
|
||
$reflection->setAccessible(true);
|
||
$result = $reflection->invoke($this->job, $input);
|
||
$this->assertEquals($expected, $result, "Failed asserting that textToFloat('$input') equals $expected. Got $result instead.");
|
||
}
|
||
|
||
|
||
public function test_simple_int(): void
|
||
{
|
||
$this->assertTextToFloat("10", 10.0);
|
||
$this->assertTextToFloat(" 42", 42.0);
|
||
}
|
||
|
||
public function test_decimal_numbers(): void
|
||
{
|
||
$this->assertTextToFloat("3,14", 3.14);
|
||
$this->assertTextToFloat(" 0,0015 ", 0.0015);
|
||
}
|
||
|
||
public function test_money_symbols_int(): void
|
||
{
|
||
$this->assertTextToFloat("5 €", 5.0);
|
||
$this->assertTextToFloat(" € 123 ", 123.0);
|
||
}
|
||
|
||
public function test_money_symbols_decimal(): void
|
||
{
|
||
$this->assertTextToFloat("7,89 €", 7.89);
|
||
$this->assertTextToFloat(" € 0,75 ", 0.75);
|
||
$this->assertTextToFloat(" €0.00402 ", 0.00402);
|
||
$this->assertTextToFloat(" 0,00429 € ", 0.00429);
|
||
}
|
||
}
|
||
|