Example #1
0
 /**
  * @test
  */
 function construct_()
 {
     $extract = array('obj' => new \stdClass());
     $cfg = array('pdo' => $this->pdo, 'extract' => $extract);
     $config = new Config($cfg, __FILE__);
     $adapter = new PdoAdapter($this->pdo);
     assertThat($config->adapter, isInstanceOf(get_class($adapter)));
     assertThat($config->extract, identicalTo($extract));
 }
 /** @test */
 public function itCanBeTraversed()
 {
     $requestParameter = $this->prophesize(Parameter::class);
     $requestParameter->getLocation()->willReturn('query');
     $requestParameter->getName()->willReturn('foo');
     $requestParameters = new Parameters([$requestParameter->reveal()]);
     assertThat($requestParameters, isInstanceOf(\Traversable::class));
     assertThat($requestParameters, containsOnlyInstancesOf(Parameter::class));
 }
 public function createApplication()
 {
     $pimple = new \Pimple();
     $dependencies = array('beforeTokenChecker' => $pimple->protect(function () {
     }));
     require SPIKA_ROOT . '/etc/app.php';
     $mailer = $this->getMockBuilder('\\Silex\\Provider\\SwiftmailerServiceProvider')->setMethods(array('send'))->disableOriginalConstructor()->getMock();
     $mailer->expects(once())->method('send')->with(isInstanceOf('Swift_Message'));
     $app['mailer'] = $mailer;
     return $app;
 }
 /** @test */
 public function itCanCreateAResponseDefinition()
 {
     $schemaFile = 'file://' . __DIR__ . '/../fixtures/petstore.json';
     $factory = new SwaggerSchemaFactory();
     $schema = $factory->createSchema($schemaFile);
     $responseDefinition = $schema->getRequestDefinition('addPet')->getResponseDefinition(200);
     assertThat($responseDefinition, isInstanceOf(ResponseDefinition::class));
     assertThat($responseDefinition->getContentTypes(), contains('application/json'));
     assertThat($responseDefinition->getBodySchema(), isType('object'));
     assertThat($responseDefinition->getStatusCode(), equalTo(200));
 }
 /** @test */
 public function itShouldLoadASchemaFromACacheStore()
 {
     $schemaFile = 'file://fake-schema.yml';
     $schema = $this->prophesize(Schema::class);
     $item = $this->prophesize(CacheItemInterface::class);
     $item->isHit()->shouldBeCalled()->willReturn(true);
     $item->get()->shouldBeCalled()->willReturn($schema);
     $cache = $this->prophesize(CacheItemPoolInterface::class);
     $cache->getItem('3f470a326a5926a2e323aaadd767c0e64302a080')->willReturn($item);
     $schemaFactory = $this->prophesize(SchemaFactory::class);
     $schemaFactory->createSchema(Argument::any())->shouldNotBeCalled();
     $cachedSchema = new CachedSchemaFactoryDecorator($cache->reveal(), $schemaFactory->reveal());
     $expectedSchema = $schema->reveal();
     $actualSchema = $cachedSchema->createSchema($schemaFile);
     assertThat($actualSchema, isInstanceOf(Schema::class));
     assertThat($actualSchema, equalTo($expectedSchema));
 }
 /**
  * @test
  * @since  4.0.0
  */
 public function unmodifiableTurnsModifiableIntoNonModifiableProperties()
 {
     assert($this->modifiableProperties->unmodifiable(), isInstanceOf(Properties::class));
 }
 /**
  * @test
  * @group  secure_string
  * @since  4.1.0
  */
 public function parseSecretValueReturnsSecretInstance()
 {
     assert((new Properties(['foo' => ['password' => 'baz']]))->parseValue('foo', 'password'), isInstanceOf(Secret::class));
 }
 /**
  * @test
  * @since  4.1.4
  */
 public function reflectClosureReturnsReflectionObject()
 {
     assert(reflect(function () {
     }), isInstanceOf(\ReflectionObject::class));
 }
Example #9
0
 /**
  * @test
  * @since  8.0.0
  */
 public function openSecureSocketReturnsStreamInstance()
 {
     $fsockopen = NewCallable::of('fsockopen')->mapCall(fopen(__FILE__, 'rb'));
     assert(IpAddress::castFrom('127.0.0.1')->openSecureSocket(443, 1, $fsockopen), isInstanceOf(Stream::class));
 }
Example #10
0
 /**
  * @test
  * @since  6.0.0
  */
 public function connectReturnsStream()
 {
     $socket = createSocket('localhost', 80)->openWith(NewCallable::of('fsockopen')->mapCall(fopen(__FILE__, 'rb')));
     assert($socket->connect(), isInstanceOf(Stream::class));
 }
 /**
  * @test
  * @since  4.0.0
  */
 public function openResourceWithCompletePathInRootReturnsInputStream()
 {
     assert($this->resourceLoader->open(__FILE__), isInstanceOf(FileInputStream::class));
 }
 /**
  * @test
  */
 public function linesOfReturnsSequence()
 {
     assert(linesOf($this->file->url()), isInstanceOf(Sequence::class));
 }
Example #13
0
 /**
  * @test
  * @since  4.0.0
  */
 public function fromPartsReturnsInstanceOfHttpUri()
 {
     assert(HttpUri::fromParts('https', 'localhost', 8080, '/index.php', 'foo=bar'), isInstanceOf(HttpUri::class));
 }
Example #14
0
 /**
  * Calls DBCore magic methods like:
  *    get[User]By[Id]($userId)
  *    get[User]By[Email]($email)
  *    get[Users]()
  *    delete[Users]($ids)
  *    delete[User]($userId)
  *    set[User]Activation($activationFieldName, $flagValue)
  *
  * @param string $methodName Name of the magic method.
  * @param array $methodParams List of dynamic parameters.
  *
  * @return mixed
  * @throws DBCoreException
  */
 public function __call($methodName, $methodParams)
 {
     if (strrpos($methodName, "ies") == strlen($methodName) - 3) {
         $methodName = substr($methodName, 0, strlen($methodName) - 3) . "ys";
     }
     /**
      * Get database record object by Id
      */
     if (preg_match("#get([a-zA-Z]+)ById#", $methodName, $matches)) {
         $dbSelector = new DBSelector($matches[1]);
         return $dbSelector->selectDBObjectById($methodParams[0]);
     }
     /**
      * Get database record object by some field value
      */
     if (preg_match("#get([a-zA-Z]+)By([a-zA-Z]+)#", $methodName, $matches)) {
         if (empty($methodParams[0])) {
             return null;
         }
         $dbSelector = new DBSelector($matches[1]);
         $fieldName = substr(strtolower(preg_replace("#([A-Z]{1})#", "_\$1", $matches[2])), 1);
         return $dbSelector->selectDBObjectByField($fieldName, $methodParams[0]);
     }
     /**
      * Get all database records
      */
     if (preg_match("#get([a-zA-Z]+)s#", $methodName, $matches)) {
         return self::Selector()->selectDBObjects();
     }
     /**
      * Delete selected records from the database
      */
     if (preg_match("#delete([a-zA-Z]+)s#", $methodName, $matches)) {
         $className = $matches[1];
         $idsList = $methodParams[0];
         $idsList = array_filter($idsList, "isInteger");
         if (!empty($idsList)) {
             $itemsNumber = count($idsList);
             $types = DBPreparedQuery::sqlSingleTypeString("i", $itemsNumber);
             $dbObject = new $className();
             if (!isInstanceOf($dbObject, $className)) {
                 throw new DBCoreException("Class with name '" . $className . "' is not exists");
             }
             $query = "DELETE FROM " . $dbObject->getTableName() . "\n                          WHERE " . $dbObject->getIdFieldName() . "\n                             IN (" . DBPreparedQuery::sqlQMString($itemsNumber) . ")";
             return self::doUpdateQuery($query, $types, $idsList);
         }
         return 0;
     }
     /**
      * Delete selected record from the database
      */
     if (preg_match("#delete([a-zA-Z]+)#", $methodName, $matches)) {
         return call_user_func(array(self::Instance(), $methodName . "s"), array($methodParams[0]));
     }
     /**
      * Set activation value of selected records
      */
     if (preg_match("#set([a-zA-Z]+)Activation#", $methodName, $matches)) {
         $className = $matches[1];
         if (strrpos($className, "ies") == strlen($className) - 3) {
             $className = substr($className, 0, strlen($className) - 3) . "y";
         } else {
             $className = substr($className, 0, strlen($className) - 1);
         }
         $idsList = $methodParams[0];
         $activationFieldName = $methodParams[1];
         $activationValue = $methodParams[2];
         if (empty($activationFieldName)) {
             throw new DBCoreException("Invalid activation field name");
         }
         $idsList = array_filter($idsList, "isInteger");
         if (!empty($idsList)) {
             $itemsNumber = count($idsList);
             $types = DBPreparedQuery::sqlSingleTypeString("i", $itemsNumber);
             $dbObject = new $className();
             if (!isInstanceOf($dbObject, $className)) {
                 throw new DBCoreException("Class with name '" . $className . "' is not exists");
             }
             $query = "UPDATE " . $dbObject->getTableName() . " SET `" . $activationFieldName . "` = '" . $activationValue . "'\n                          WHERE " . $dbObject->getIdFieldName() . " IN (" . DBPreparedQuery::sqlQMString($itemsNumber) . ")";
             return self::doUpdateQuery($query, $types, $idsList);
         }
     }
     throw new DBCoreException('No such method "' . $methodName . '"');
 }