getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); $stub->setStyleByArray(['index' => 1]); self::assertEquals(1, $stub->getIndex()); } /** * Test setBoolVal, setIntVal, setFloatVal, setEnumVal with normal value. */ public function testSetValNormal(): void { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); self::assertTrue(self::callProtectedMethod($stub, 'setBoolVal', [true, false])); self::assertEquals(12, self::callProtectedMethod($stub, 'setIntVal', [12, 200])); self::assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', [871.1, 2.1])); self::assertEquals(871.1, self::callProtectedMethod($stub, 'setFloatVal', ['871.1', 2.1])); self::assertEquals('a', self::callProtectedMethod($stub, 'setEnumVal', ['a', ['a', 'b'], 'b'])); } /** * Test setBoolVal, setIntVal, setFloatVal, setEnumVal with default value. */ public function testSetValDefault(): void { $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); self::assertNotTrue(self::callProtectedMethod($stub, 'setBoolVal', ['a', false])); self::assertEquals(200, self::callProtectedMethod($stub, 'setIntVal', ['foo', 200])); self::assertEquals(2.1, self::callProtectedMethod($stub, 'setFloatVal', ['foo', 2.1])); self::assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', [null, ['a', 'b'], 'b'])); } /** * Test setEnumVal exception. */ public function testSetValEnumException(): void { $this->expectException(InvalidArgumentException::class); $stub = $this->getMockForAbstractClass('\PhpOffice\PhpWord\Style\AbstractStyle'); self::assertEquals('b', self::callProtectedMethod($stub, 'setEnumVal', ['z', ['a', 'b'], 'b'])); } /** * Helper function to call protected method. * * @param mixed $object * @param string $method */ public static function callProtectedMethod($object, $method, array $args = []) { $class = new ReflectionClass(get_class($object)); $method = $class->getMethod($method); $method->setAccessible(true); return $method->invokeArgs($object, $args); } }