Author: Nate Brunette (n@tebru.net)
Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $srcDir = $input->getArgument('sourceDirectory');
     $cacheDir = $input->getArgument('cacheDirectory');
     $retrofit = new Retrofit($cacheDir);
     $count = $retrofit->cacheAll($srcDir);
     $output->writeln(sprintf('<info>Compiled %s %s successfully</info>', $count, $count === 1 ? 'class' : 'classes'));
 }
 public function testCreateCache()
 {
     $serviceResolver = Mockery::mock(ServiceResolver::class);
     $generator = Mockery::mock(Generator::class);
     $generator->shouldReceive('createAndWrite')->times(1)->with(MockServiceUrlRequest::class)->andReturnNull();
     $generator->shouldReceive('createAndWrite')->times(1)->with(MockServiceBody::class)->andReturnNull();
     $retrofit = new Retrofit($serviceResolver, $generator);
     $retrofit->registerServices([MockServiceUrlRequest::class, MockServiceBody::class]);
     $numberCached = $retrofit->createCache();
     $this->assertEquals(2, $numberCached);
 }
 /**
  * Warms up the cache.
  *
  * Gets array of services from compiler pass and cache them
  *
  * @param string $cacheDir The cache directory
  */
 public function warmUp($cacheDir)
 {
     $retrofit = Retrofit::builder()->setCacheDir($cacheDir)->setEventDispatcher($this->container->get('event_dispatcher'))->build();
     /** @var ServicesCollection $servicesCollection */
     $servicesCollection = $this->container->get(RegisterCompilerPass::COLLECTION_ID);
     $retrofit->registerServices($servicesCollection->getServices());
     $retrofit->createCache();
 }
Example #4
0
 /**
  * @param BeforeSuiteScope $scope
  *
  * @BeforeSuite
  */
 public static function prepare(BeforeSuiteScope $scope)
 {
     define('PROJECT_ROOT', __DIR__ . '/../../..');
     $loader = (require PROJECT_ROOT . '/vendor/autoload.php');
     $loader->addPsr4(Retrofit::NAMESPACE_PREFIX . '\\', PROJECT_ROOT . '/cache/tests/retrofit');
     AnnotationRegistry::registerLoader([$loader, 'loadClass']);
     $retrofit = Retrofit::builder()->setCacheDir(PROJECT_ROOT . '/cache/tests')->build();
     $retrofit->registerServices([ApiClient::class]);
     $retrofit->createCache();
 }
 public function testCanUseAllSetters()
 {
     $eventDispatcher = Mockery::mock(EventDispatcherInterface::class);
     $generator = Mockery::mock(Generator::class);
     $serviceResolvoer = Mockery::mock(ServiceResolver::class);
     $eventDispatcher->shouldReceive('addListener')->times(1)->with(StartEvent::NAME, Mockery::type(DynamoStartListener::class));
     $eventDispatcher->shouldReceive('addListener')->times(1)->with(MethodEvent::NAME, Mockery::type(DynamoMethodListener::class));
     $builder = Retrofit::builder()->setCacheDir('')->setEventDispatcher($eventDispatcher)->setGenerator($generator)->setServiceResolver($serviceResolvoer);
     $retrofit = $builder->build();
     $this->assertInstanceOf(Retrofit::class, $retrofit);
 }
Example #6
0
<?php

/*
 * Copyright (c) Nate Brunette.
 * Distributed under the MIT License (http://opensource.org/licenses/MIT)
 */
use Doctrine\Common\Annotations\AnnotationRegistry;
use Tebru\Retrofit\Retrofit;
$loader = (require __DIR__ . '/../vendor/autoload.php');
$loader->addPsr4(Retrofit::NAMESPACE_PREFIX . '\\', __DIR__ . '/../cache/tests/retrofit');
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
define('TEST_DIR', __DIR__);
$retrofit = Retrofit::builder()->setCacheDir(__DIR__ . '/../cache/tests')->build();
$retrofit->cacheAll(__DIR__ . '/Mock');
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     $retrofit = new Retrofit(TEST_DIR . '/../cache/tests');
     $retrofit->cacheAll(TEST_DIR . '/Mock');
 }
Example #8
0
 public function testCacheAll()
 {
     $retrofit = new Retrofit(self::$cacheDir);
     $numberCached = $retrofit->cacheAll(TEST_DIR . '/Mock');
     $this->assertEquals(4, $numberCached);
 }