get_class_methods example

'flipimage',
            'flopimage',
            'readimage',
            'readimageblob',
        );

        // Now, test for deep requirements within Imagick.         if ( ! defined( 'imagick::COMPRESSION_JPEG' ) ) {
            return false;
        }

        $class_methods = array_map( 'strtolower', get_class_methods( 'Imagick' ) );
        if ( array_diff( $required_methods$class_methods ) ) {
            return false;
        }

        return true;
    }

    /** * Checks to see if editor supports the mime-type specified. * * @since 3.5.0 * * @param string $mime_type * @return bool */
parent::setUp();

    // Construct a state object used for testing logger assertions.     $this->state = new State(new KeyValueMemoryFactory());

    // Create a mock logger to set a flag in the resulting state.     $logger = $this->prophesize('Drupal\Core\Logger\LoggerChannelInterface');
    // Safely ignore the cron success message.     $logger->info('Cron run completed.')->shouldBeCalled();
    // Set a flag to track when a message is logged by adding a callback     // function for each logging method.     foreach (get_class_methods(LoggerInterface::class) as $logger_method) {
      $logger->{$logger_method}(Argument::cetera())->will(function D) {
        \Drupal::state()->set('cron_test.message_logged', TRUE);
      });
    }

    // Create a logger factory to produce the resulting logger.     $logger_factory = $this->prophesize('Drupal\Core\Logger\LoggerChannelFactoryInterface');
    $logger_factory->get(Argument::exact('cron'))->willReturn($logger->reveal());

    // Create a mock time service.     $time = $this->prophesize('Drupal\Component\Datetime\TimeInterface');

    
$message = $error->getMessage();
        preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $message$matches);
        if (!$matches) {
            return null;
        }

        $className = $matches[1];
        $methodName = $matches[2];

        $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName$className);

        if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) {
            // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)             return new UndefinedMethodError($message$error);
        }

        $candidates = [];
        foreach ($methods as $definedMethodName) {
            $lev = levenshtein($methodName$definedMethodName);
            if ($lev <= \strlen($methodName) / 3 || str_contains($definedMethodName$methodName)) {
                $candidates[] = $definedMethodName;
            }
        }

        
$message = $this->_messageTemplates[$messageKey];

        if (null !== ($translator = $this->getTranslator())) {
            if ($translator->isTranslated($messageKey)) {
                $message = $translator->translate($messageKey);
            } else {
                $message = $translator->translate($message);
            }
        }

        if (is_object($value)) {
            if (!in_array('__toString', get_class_methods($value))) {
                $value = get_class($value) . ' object';
            } else {
                $value = $value->__toString();
            }
        } else {
            $value = implode((array) $value);
        }

        if ($this->getObscureValue()) {
            $value = str_repeat('*', strlen($value));
        }

        

  protected function getMockSource() {
    $this->createMock('\Iterator');

    $class = 'Drupal\migrate\Plugin\migrate\source\SourcePluginBase';
    $source = $this->getMockBuilder($class)
      ->disableOriginalConstructor()
      ->onlyMethods(get_class_methods($class))
      ->getMockForAbstractClass();
    $source->expects($this->once())
      ->method('rewind')
      ->willReturn(TRUE);
    $source->expects($this->any())
      ->method('initializeIterator')
      ->willReturn([]);
    $source->expects($this->any())
      ->method('valid')
      ->will($this->onConsecutiveCalls(TRUE, FALSE));

    

    $this->assertSame('en', $this->entity->language()->getId());
  }

  /** * Setup for the tests of the ::load() method. */
  public function setupTestLoad() {
    // Base our mocked entity on a real entity class so we can test if calling     // Entity::load() on the base class will bubble up to an actual entity.     $this->entityTypeId = 'entity_test_mul';
    $methods = get_class_methods(EntityTestMul::class);
    unset($methods[array_search('load', $methods)]);
    unset($methods[array_search('loadMultiple', $methods)]);
    unset($methods[array_search('create', $methods)]);
    $this->entity = $this->getMockBuilder(EntityTestMul::class)
      ->disableOriginalConstructor()
      ->onlyMethods($methods)
      ->getMock();

  }

  /** * @covers ::load * * Tests Entity::load() when called statically on a subclass of Entity. */
return $object->$item;
        }
    }

    static $cache = [];

    $class = \get_class($object);

    // object method     // precedence: getXxx() > isXxx() > hasXxx()     if (!isset($cache[$class])) {
        $methods = get_class_methods($object);
        sort($methods);
        $lcMethods = array_map(function D$value) { return strtr($value, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')}$methods);
        $classCache = [];
        foreach ($methods as $i => $method) {
            $classCache[$method] = $method;
            $classCache[$lcName = $lcMethods[$i]] = $method;

            if ('g' === $lcName[0] && 0 === strpos($lcName, 'get')) {
                $name = substr($method, 3);
                $lcName = substr($lcName, 3);
            } elseif ('i' === $lcName[0] && 0 === strpos($lcName, 'is')) {
                
if (\count($alternatives) > 0) {
            $message .= sprintf(', did you mean "%s"?', implode('", "', $alternatives));
        } else {
            $message .= sprintf('. Available methods: "%s".', implode('", "', $collection));
        }

        return $message;
    }

    private function getClassMethodsWithoutMagicMethods($classOrObject): array
    {
        $methods = get_class_methods($classOrObject);

        return array_filter($methodsfn (string $method) => 0 !== strncmp($method, '__', 2));
    }
}

    public function __construct()
    {
        $this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')';
        $this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')';

        static $cache;
        if (!isset($cache[get_class($this)]))
        {
            $all_methods = get_class_methods($this);

            foreach ($all_methods as $method)
            {
                if (strtolower(substr($method, 0, 5)) === 'date_')
                {
                    $cache[get_class($this)][] = $method;
                }
            }
        }

        foreach ($cache[get_class($this)] as $method)
        {
if (\count($alternatives) > 0) {
            $message .= sprintf(', did you mean "%s"?', implode('", "', $alternatives));
        } else {
            $message .= sprintf('. Available methods: "%s".', implode('", "', $collection));
        }

        return $message;
    }

    private function getClassMethodsWithoutMagicMethods($classOrObject): array
    {
        $methods = get_class_methods($classOrObject);

        return array_filter($methodsfn (string $method) => 0 !== strncmp($method, '__', 2));
    }
}
return $resource;
    }

    /** * @return resource */
    private function createStream(RequestInterface $request, array $options)
    {
        static $methods;
        if (!$methods) {
            $methods = \array_flip(\get_class_methods(__CLASS__));
        }

        if (!\in_array($request->getUri()->getScheme()['http', 'https'])) {
            throw new RequestException(\sprintf("The scheme '%s' is not supported.", $request->getUri()->getScheme())$request);
        }

        // HTTP/1.1 streams using the PHP stream wrapper require a         // Connection: close header         if ($request->getProtocolVersion() == '1.1'
            && !$request->hasHeader('Connection')
        ) {
            
$lock->expects($this->once())
      ->method('release')
      ->with($lock_name);
    $lock->expects($this->exactly(2))
      ->method($this->anything());
    $container->set('lock', $lock);

    $cache_tag_invalidator = $this->createMock('Drupal\Core\Cache\CacheTagsInvalidator');
    $container->set('cache_tags.invalidator', $cache_tag_invalidator);

    \Drupal::setContainer($container);
    $methods = get_class_methods('Drupal\comment\Entity\Comment');
    unset($methods[array_search('preSave', $methods)]);
    unset($methods[array_search('postSave', $methods)]);
    $methods[] = 'invalidateTagsOnSave';
    $comment = $this->getMockBuilder('Drupal\comment\Entity\Comment')
      ->disableOriginalConstructor()
      ->onlyMethods($methods)
      ->getMock();
    $comment->expects($this->once())
      ->method('isNew')
      ->willReturn(TRUE);
    $comment->expects($this->once())
      
// Implementation should support the passed mime type.         if ( isset( $args['mime_type'] ) &&
            ! call_user_func(
                array( $implementation, 'supports_mime_type' ),
                $args['mime_type']
            ) ) {
            continue;
        }

        // Implementation should support requested methods.         if ( isset( $args['methods'] ) &&
            array_diff( $args['methods']get_class_methods( $implementation ) ) ) {

            continue;
        }

        // Implementation should ideally support the output mime type as well if set and different than the passed type.         if (
            isset( $args['mime_type'] ) &&
            isset( $args['output_mime_type'] ) &&
            $args['mime_type'] !== $args['output_mime_type'] &&
            ! call_user_func( array( $implementation, 'supports_mime_type' )$args['output_mime_type'] )
        ) {
            
$message = $error->getMessage();
        preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $message$matches);
        if (!$matches) {
            return null;
        }

        $className = $matches[1];
        $methodName = $matches[2];

        $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName$className);

        if ('' === $methodName || !class_exists($className) || null === $methods = get_class_methods($className)) {
            // failed to get the class or its methods on which an unknown method was called (for example on an anonymous class)             return new UndefinedMethodError($message$error);
        }

        $candidates = [];
        foreach ($methods as $definedMethodName) {
            $lev = levenshtein($methodName$definedMethodName);
            if ($lev <= \strlen($methodName) / 3 || str_contains($definedMethodName$methodName)) {
                $candidates[] = $definedMethodName;
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.