Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Do not use static in callables #785

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased](https://github.com/FakerPHP/Faker/compare/v1.23.0...main)

- Fixed polish license plates (#685)
- 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/Faker/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/Faker/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);
Comment on lines +19 to +20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests are not very useful other than letting us see whether we still trigger any deprecations here.

}

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);
}
}
Loading