-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
165 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,40 @@ | ||
UPGRADE 2.x | ||
=========== | ||
|
||
UPGRADE FROM 2.7 to 2.8 | ||
======================= | ||
|
||
### Timezone detector | ||
|
||
``Sonata\IntlBundle\Timezone\TimezoneAwareInterface`` was added in order to provide | ||
timezone detection for any user class. | ||
|
||
Timezone inference based on the ``Sonata\UserBundle\Model\User::getTimezone()`` method | ||
is deprecated and will be dropped in 3.0 version. | ||
You MUST implement ``Sonata\IntlBundle\Timezone\TimezoneAwareInterface`` explicitly | ||
in your user class. | ||
|
||
Before: | ||
```php | ||
class User | ||
{ | ||
// ... | ||
} | ||
``` | ||
|
||
After: | ||
```php | ||
class User implements \Sonata\IntlBundle\Timezone\TimezoneAwareInterface | ||
{ | ||
// ... | ||
} | ||
``` | ||
|
||
UPGRADE FROM 2.3 to 2.4 | ||
======================= | ||
|
||
### Tests | ||
|
||
All files under the ``Tests`` directory are now correctly handled as internal test classes. | ||
You can't extend them anymore, because they are only loaded when running internal tests. | ||
All files under the ``Tests`` directory are now correctly handled as internal test classes. | ||
You can't extend them anymore, because they are only loaded when running internal tests. | ||
More information can be found in the [composer docs](https://getcomposer.org/doc/04-schema.md#autoload-dev). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\IntlBundle\Timezone; | ||
|
||
/** | ||
* @author Javier Spagnoletti <[email protected]> | ||
*/ | ||
interface TimezoneAwareInterface | ||
{ | ||
public function getTimezone(): ?string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\IntlBundle\Timezone; | ||
|
||
/** | ||
* Basic Implementation of TimezoneAwareInterface. | ||
* | ||
* @author Javier Spagnoletti <[email protected]> | ||
*/ | ||
trait TimezoneAwareTrait | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $timezone; | ||
|
||
final public function getTimezone(): ?string | ||
{ | ||
return $this->timezone; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
namespace Sonata\IntlBundle\Tests\Timezone; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Sonata\IntlBundle\Timezone\TimezoneAwareInterface; | ||
use Sonata\IntlBundle\Timezone\TimezoneAwareTrait; | ||
use Sonata\IntlBundle\Timezone\UserBasedTimezoneDetector; | ||
use Sonata\UserBundle\Model\User; | ||
use Sonata\UserBundle\SonataUserBundle; | ||
|
@@ -23,30 +25,60 @@ | |
/** | ||
* @author Emmanuel Vella <[email protected]> | ||
*/ | ||
class UserBasedTimezoneDetectorTest extends TestCase | ||
final class UserBasedTimezoneDetectorTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
if (!class_exists(SonataUserBundle::class)) { | ||
$this->markTestSkipped('SonataUserBundle must be installed to run this test.'); | ||
} | ||
} | ||
|
||
public static function timezoneProvider() | ||
public static function timezoneProvider(): iterable | ||
{ | ||
return [ | ||
['Europe/Paris'], | ||
[null], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider timezoneProvider | ||
*/ | ||
public function testUserTimezoneDetection(?string $timezone): void | ||
{ | ||
$user = new class($timezone) implements TimezoneAwareInterface { | ||
use TimezoneAwareTrait; | ||
|
||
public function __construct(?string $timezone) | ||
{ | ||
$this->timezone = $timezone; | ||
} | ||
}; | ||
|
||
$token = $this->createMock(TokenInterface::class); | ||
$token | ||
->expects($this->once()) | ||
->method('getUser') | ||
->willReturn($user) | ||
; | ||
|
||
$storage = $this->createMock(TokenStorageInterface::class); | ||
|
||
$storage | ||
->expects($this->once()) | ||
->method('getToken') | ||
->willReturn($token) | ||
; | ||
|
||
$timezoneDetector = new UserBasedTimezoneDetector($storage); | ||
$this->assertSame($timezone, $timezoneDetector->getTimezone()); | ||
} | ||
|
||
/** | ||
* @dataProvider timezoneProvider | ||
* | ||
* @group legacy | ||
*/ | ||
public function testDetectsTimezoneForUser($timezone) | ||
public function testDetectsTimezoneForUser(?string $timezone): void | ||
{ | ||
if (!class_exists(SonataUserBundle::class)) { | ||
$this->markTestSkipped('SonataUserBundle must be installed to run this test.'); | ||
} | ||
|
||
$user = $this->createMock(User::class); | ||
$user | ||
->method('getTimezone') | ||
|
@@ -70,7 +102,7 @@ public function testDetectsTimezoneForUser($timezone) | |
$this->assertSame($timezone, $timezoneDetector->getTimezone()); | ||
} | ||
|
||
public function testTimezoneNotDetected() | ||
public function testTimezoneNotDetected(): void | ||
{ | ||
$storage = $this->createMock(TokenStorageInterface::class); | ||
|
||
|