Debian Codegraph @

lib/php/test/Unit/Lib/Factory/TStringFuncFactoryTest.php

raw
1 <?php
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 namespace Test\Thrift\Unit\Lib\Factory;
23
24 use phpmock\phpunit\PHPMock;
25 use PHPUnit\Framework\TestCase;
26 use Test\Thrift\Unit\Lib\ReflectionHelper;
27 use Thrift\Factory\TStringFuncFactory;
28 use Thrift\StringFunc\Core;
29 use Thrift\StringFunc\Mbstring;
30 use Thrift\StringFunc\TStringFunc;
31
32 class TStringFuncFactoryTest extends TestCase
33 {
34 use PHPMock;
35 use ReflectionHelper;
36
37 /**
38 * @dataProvider createDataProvider
39 */
40 public function testCreate(
41 $mbstringFuncOverload,
42 $expectedClass
43 ) {
44 $this->getFunctionMock('Thrift\Factory', 'ini_get')
45 ->expects($this->once())
46 ->with('mbstring.func_overload')
47 ->willReturn($mbstringFuncOverload);
48
49 $factory = new TStringFuncFactory();
50 /**
51 * it is a hack to nullable the instance of TStringFuncFactory, and get a new instance based on the new ini_get value
52 */
53 $this->setPropertyValue($factory, '_instance', null);
54
55 $stringFunc = $factory::create();
56
57 $this->assertInstanceOf(TStringFunc::class, $stringFunc);
58 $this->assertInstanceOf($expectedClass, $stringFunc);
59 }
60
61 public function createDataProvider()
62 {
63 yield 'mbstring' => [
64 'mbstring.func_overload' => 2,
65 'expected' => Mbstring::class
66 ];
67
68 yield 'string' => [
69 'mbstring.func_overload' => 0,
70 'expected' => Core::class
71 ];
72 }
73 }