Skip to content

Commit

Permalink
Fix: Do not use static in callables (#785) (#786)
Browse files Browse the repository at this point in the history
* Fix: Add tests

* Fix: Do not use static in callables
  • Loading branch information
localheinz authored Sep 26, 2023
1 parent 16037e0 commit 5269675
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Removed legacy autoloader (#762)
- Removed functionality for populating ORM entities and models (#764)
- Added a PHP version support policy (#752)
- Stopped using `static` in callables in `Provider\pt_BR\PhoneNumber` (#785)

## [2023-06-12, v1.23.0](https://github.com/FakerPHP/Faker/compare/v1.22.0..v1.23.0)

Expand Down
6 changes: 3 additions & 3 deletions src/Provider/pt_BR/PhoneNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static function phone($formatted = true)
['landline', null],
]);

return call_user_func("static::{$options[0]}", $formatted, $options[1]);
return call_user_func([static::class, $options[0]], $formatted, $options[1]);
}

/**
Expand Down Expand Up @@ -135,7 +135,7 @@ public function phoneNumber()
{
$method = static::randomElement(['cellphoneNumber', 'landlineNumber']);

return call_user_func("static::$method", true);
return call_user_func([static::class, $method], true);
}

/**
Expand All @@ -145,6 +145,6 @@ public static function phoneNumberCleared()
{
$method = static::randomElement(['cellphoneNumber', 'landlineNumber']);

return call_user_func("static::$method", false);
return call_user_func([static::class, $method], false);
}
}
51 changes: 51 additions & 0 deletions test/Provider/pt_BR/PhoneNumberTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Faker\Test\Provider\pt_BR;

use Faker\Provider;
use Faker\Test;

/**
* @covers \Faker\Provider\pt_BR\PhoneNumber
*/
final class PhoneNumberTest extends Test\TestCase
{
public function testPhoneReturnsPhoneNumberWhenArgumentIsFalse(): void
{
$phoneNumber = $this->faker->phone(false);

self::assertIsString($phoneNumber);
self::assertNotEmpty($phoneNumber);
}

public function testPhoneReturnsPhoneNumberWhenArgumentIsTrue(): void
{
$phoneNumber = $this->faker->phone(true);

self::assertIsString($phoneNumber);
self::assertNotEmpty($phoneNumber);
}

public function testPhoneNumberReturnsPhoneNumber(): void
{
$phoneNumber = $this->faker->phoneNumber();

self::assertIsString($phoneNumber);
self::assertNotEmpty($phoneNumber);
}

public function testPhoneNumberClearedReturnsPhoneNumber(): void
{
$phoneNumber = $this->faker->phoneNumberCleared();

self::assertIsString($phoneNumber);
self::assertNotEmpty($phoneNumber);
}

protected function getProviders(): iterable
{
yield new Provider\pt_BR\PhoneNumber($this->faker);
}
}

0 comments on commit 5269675

Please sign in to comment.