File: SettingsTest.php

package info (click to toggle)
php-nesbot-carbon 2.65.0-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 18,280 kB
  • sloc: php: 157,346; xml: 42; makefile: 26; sh: 12
file content (52 lines) | stat: -rw-r--r-- 1,779 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php

declare(strict_types=1);

/**
 * This file is part of the Carbon package.
 *
 * (c) Brian Nesbitt <brian@nesbot.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Tests\CarbonImmutable;

use Carbon\CarbonImmutable as Carbon;
use Tests\AbstractTestCase;

class SettingsTest extends AbstractTestCase
{
    public function testSettings()
    {
        $paris = Carbon::parse('2018-01-31 00:00:00')->settings([
            'timezone' => 'Europe/Paris',
            'locale' => 'fr_FR',
            'monthOverflow' => true,
            'yearOverflow' => true,
        ]);
        $this->assertEquals([
            'timezone' => 'Europe/Paris',
            'locale' => 'fr_FR',
            'monthOverflow' => true,
            'yearOverflow' => true,
        ], $paris->getSettings());
        $saoPaulo = Carbon::parse('2018-01-31 00:00:00')->settings([
            'timezone' => 'America/Sao_Paulo',
            'locale' => 'pt',
            'monthOverflow' => false,
            'yearOverflow' => false,
        ]);
        $this->assertEquals([
            'timezone' => 'America/Sao_Paulo',
            'locale' => 'pt',
            'monthOverflow' => false,
            'yearOverflow' => false,
        ], $saoPaulo->getSettings());

        $this->assertSame('2 jours 1 heure avant', $paris->addMonth()->from(Carbon::parse('2018-03-05', 'UTC'), null, false, 3));
        $this->assertSame('4 dias 21 horas antes', $saoPaulo->addMonth()->from(Carbon::parse('2018-03-05', 'UTC'), null, false, 3));
        $this->assertSame('2 jours et une heure avant', $paris->addMonth()->from(Carbon::parse('2018-03-05', 'UTC'), ['parts' => 3, 'join' => true, 'aUnit' => true]));
    }
}