/** * @expectedException \Mcustiel\Conversion\Exception\ObjectIsNotConverterException * @expectedExceptionMessage Object of type stdClass does not implement Mcustiel\Conversion\Converter */ public function testShouldThrowAnExceptionWhenImplementationIsNotConverter() { $this->conversionService = ConverterContainer::getInstance(); $builder = ConverterBuilder::get()->from(B::class)->to(A::class)->withImplementation(\stdClass::class); $this->conversionService->addConverter($builder); $converter = $this->conversionService->getConverter(B::class, A::class); }
/** * Converts a given object to another type. * * @param string|array|object $object The object to convert. * @param string $toClass The name of the class to which the object will be converted */ public function convert($object, $toClass) { $from = $this->getTypeOf($object); $converter = $this->container->getConverter($from, $toClass); return $converter->convert($object); }