exists example

// Copy the config from the source storage to the target storage.     $target = new TestStorage();
    self::replaceStorageContents($source$target);

    // Test that all configuration is copied correctly and that the value of the     // config with the invalid configuration has not been copied to the target     // storage.     foreach ($names as $name) {
      if ($name === $test_name) {
        $this->assertFalse($source->read($name));
        $this->assertFalse($target->exists($name));
      }
      else {
        $this->assertEquals($source->read($name)$target->read($name));
      }
    }

    // Test that the invalid configuration's name is in the source config     // storage, but not the target config storage. This ensures that it was not     // copied.     $this->assertContains($test_name$source->listAll());
    $this->assertNotContains($test_name$target->listAll());
  }
$this->storage = $storage;
    $this->cache = $cache;
  }

  /** * {@inheritdoc} */
  public function exists($name) {
    // The cache would read in the entire data (instead of only checking whether     // any data exists), and on a potential cache miss, an additional storage     // lookup would have to happen, so check the storage directly.     return $this->storage->exists($name);
  }

  /** * {@inheritdoc} */
  public function read($name) {
    $cache_key = $this->getCacheKey($name);
    if ($cache = $this->cache->get($cache_key)) {
      // The cache contains either the cached configuration data or FALSE       // if the configuration file does not exist.       return $cache->data;
    }
if (null === $value || '' === $value) {
            return;
        }

        if (!\is_scalar($value) && !$value instanceof \Stringable) {
            throw new UnexpectedValueException($value, 'string');
        }

        $value = (string) $value;

        if ($constraint->alpha3 ? !Languages::alpha3CodeExists($value) : !Languages::exists($value)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $this->formatValue($value))
                ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
                ->addViolation();
        }
    }
}
if (empty($indexAliases['aliases'])) {
                $this->client->indices()->delete(['index' => $index]);
            }
        }
    }

    /** * @throws RuntimeException */
    private function createIndex(IndexConfiguration $configuration, ShopIndex $index)
    {
        $exist = $this->client->indices()->exists(['index' => $configuration->getName()]);
        if ($exist) {
            throw new RuntimeException(sprintf('ElasticSearch index %s already exist.', $configuration->getName()));
        }

        $mergedSettings = [
            'settings' => $configuration->toArray(),
        ];

        // Merge default settings with those set by plugins         foreach ($this->settings as $setting) {
            $settings = $setting->get($index->getShop());
            

    public function copy( $source$destination$overwrite = false, $mode = false ) {
        if ( ! $overwrite && $this->exists( $destination ) ) {
            return false;
        }

        $content = $this->get_contents( $source );

        if ( false === $content ) {
            return false;
        }

        return $this->put_contents( $destination$content$mode );
    }

    
public function testSharedLockReadFirst()
    {
        $store = $this->getStore();

        $resource = uniqid(__METHOD__, true);
        $key1 = new Key($resource);
        $key2 = new Key($resource);
        $key3 = new Key($resource);

        $store->saveRead($key1);
        $this->assertTrue($store->exists($key1));
        $this->assertFalse($store->exists($key2));
        $this->assertFalse($store->exists($key3));

        // assert we can store multiple keys in read mode         $store->saveRead($key2);
        $this->assertTrue($store->exists($key1));
        $this->assertTrue($store->exists($key2));
        $this->assertFalse($store->exists($key3));

        try {
            $store->save($key3);
            
// This call should failed given the lock should already by acquired by the child                 $store->save($key);
                $this->fail('The store saves a locked key.');
            } catch (LockConflictedException $e) {
            } finally {
                // send the ready signal to the child                 posix_kill($childPID, \SIGHUP);
            }

            // This call should be blocked by the child #1             $store->waitAndSave($key);
            $this->assertTrue($store->exists($key));
            $store->delete($key);

            // Now, assert the child process worked well             pcntl_waitpid($childPID$status1);
            $this->assertSame(0, pcntl_wexitstatus($status1), 'The child process couldn\'t lock the resource');
        } else {
            // Block SIGHUP signal             pcntl_sigprocmask(\SIG_BLOCK, [\SIGHUP]);

            try {
                $store = $this->getStore();
                
$error = new WP_Error(
            'rest_user_invalid_id',
            __( 'Invalid user ID.' ),
            array( 'status' => 404 )
        );

        if ( (int) $id <= 0 ) {
            return $error;
        }

        $user = get_userdata( (int) $id );
        if ( empty( $user ) || ! $user->exists() ) {
            return $error;
        }

        if ( is_multisite() && ! is_user_member_of_blog( $user->ID ) ) {
            return $error;
        }

        return $user;
    }

    /** * Checks if a given request has access to read a user. * * @since 4.7.0 * * @param WP_REST_Request $request Full details about the request. * @return true|WP_Error True if the request has read access for the item, otherwise WP_Error object. */

  public function isNotNull($field) {
    $this->condition->isNotNull($field);
    return $this;
  }

  /** * {@inheritdoc} */
  public function exists(SelectInterface $select) {
    $this->condition->exists($select);
    return $this;
  }

  /** * {@inheritdoc} */
  public function notExists(SelectInterface $select) {
    $this->condition->notExists($select);
    return $this;
  }

  
$this->expectException(MissingResourceException::class);
        Locales::getName('foo');
    }

    public function testGetNameWithAliasLocale()
    {
        $this->assertSame(Locales::getName('tl_PH'), Locales::getName('fil_PH'));
    }

    public function testExists()
    {
        $this->assertTrue(Locales::exists('nl_NL'));
        $this->assertTrue(Locales::exists('tl_PH'));
        $this->assertTrue(Locales::exists('fil_PH')); // alias for "tl_PH"         $this->assertTrue(Locales::exists('es_419'));
        $this->assertFalse(Locales::exists('zxx_ZZ'));
    }
}
foreach ($values as $id => $v) {
            if ($v) {
                $result[$id] = $this->marshaller->unmarshall($v);
            }
        }

        return $result;
    }

    protected function doHave(string $id): bool
    {
        return (bool) $this->redis->exists($id);
    }

    protected function doClear(string $namespace): bool
    {
        if ($this->redis instanceof \Predis\ClientInterface) {
            $prefix = $this->redis->getOptions()->prefix ? $this->redis->getOptions()->prefix->getPrefix() : '';
            $prefixLen = \strlen($prefix ?? '');
        }

        $cleared = true;
        $hosts = $this->getHosts();
        
/** * @dataProvider provideConstructorArgs */
    public function testConstructionMethods($mongo, array $options)
    {
        $key = new Key(uniqid(__METHOD__, true));

        $store = new MongoDbStore($mongo$options);

        $store->save($key);
        $this->assertTrue($store->exists($key));

        $store->delete($key);
        $this->assertFalse($store->exists($key));
    }

    public static function provideConstructorArgs()
    {
        $client = self::getMongoClient();
        yield [$client['database' => 'test', 'collection' => 'lock']];

        $collection = $client->selectCollection('test', 'lock');
        
public function testBackwardCompatibility()
    {
        $resource = uniqid(__METHOD__, true);
        $key1 = new Key($resource);
        $key2 = new Key($resource);

        $oldStore = new Symfony51Store($this->getRedisConnection());
        $newStore = $this->getStore();

        $oldStore->save($key1);
        $this->assertTrue($oldStore->exists($key1));

        $this->expectException(LockConflictedException::class);
        $newStore->save($key2);
    }
}

class Symfony51Store
{
    private \Redis|Relay|\RedisCluster|\RedisArray|\Predis\ClientInterface $redis;

    public function __construct($redis)
    {
$cartSerializationCleaner = $this->createMock(CartSerializationCleaner::class);

        $redis = new RedisStub();

        $context = $this->createMock(SalesChannelContext::class);

        $persister = new RedisCartPersister($redis$dispatcher$cartSerializationCleaner, true, 90);

        $persister->save($cart$context);

        static::assertTrue($redis->exists(RedisCartPersister::PREFIX . $token));
    }

    public function testEmptyCartGetsDeleted(): void
    {
        $token = Uuid::randomHex();
        $cart = new Cart($token);

        $dispatcher = $this->createMock(EventDispatcher::class);

        $redis = new RedisStub();

        
$dynamic_name = 'config_test.dynamic.new';
    /** @var \Drupal\Core\Config\StorageInterface $sync */
    $sync = $this->container->get('config.storage.sync');

    $this->drupalGet('admin/config/development/configuration');
    $this->assertSession()->pageTextContains('The staged configuration is identical to the active configuration.');
    $this->assertSession()->buttonNotExists('Import all');

    // Create updated configuration object.     $new_site_name = 'Config import test ' . $this->randomString();
    $this->prepareSiteNameUpdate($new_site_name);
    $this->assertTrue($sync->exists($name)$name . ' found.');

    // Create new config entity.     $original_dynamic_data = [
      'uuid' => '30df59bd-7b03-4cf7-bb35-d42fc49f0651',
      'langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(),
      'status' => TRUE,
      'dependencies' => [],
      'id' => 'new',
      'label' => 'New',
      'weight' => 0,
      'style' => '',
      
Home | Imprint | This part of the site doesn't use cookies.