Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(WPDb) add see|dontSee|grab|dontHave (site)transient methods, fixes #664 #666

Merged
merged 4 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ name: docs
on:
pull_request:
paths:
- "docs/**"
- "mkdocs.yml"
- ".github/workflows/docs.yml"
- 'docs/**'
- 'mkdocs.yml'
- '.github/workflows/docs.yml'
push:
paths:
- "docs/**"
- "mkdocs.yml"
- ".github/workflows/docs.yml"
- 'docs/**'
- 'mkdocs.yml'
- '.github/workflows/docs.yml'
branches:
- master
permissions:
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/phpcbf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ name: "PHPCBF automatically fix violations"
on: # yamllint disable-line rule:truthy
pull_request:
paths:
- "src/**"
- "includes/**"
- ".github/workflows/phpcbf.yml"
- 'src/**'
- 'includes/**'
- '.github/workflows/phpcbf.yml'
push:
paths:
- "src/**"J
- "includes/**"
- ".github/workflows/phpcbf.yml"
- 'src/**'
- 'includes/**'
- '.github/workflows/phpcbf.yml'
branches:
- master

Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ name: "Static Analysis"
on: # yamllint disable-line rule:truthy
pull_request:
paths:
- "src/**"
- "includes/**"
- "tests/**"
- "composer.json"
- ".github/workflows/static-analysis.yml"
- 'src/**'
- 'includes/**'
- 'tests/**'
- 'composer.json'
- '.github/workflows/static-analysis.yml'
push:
paths:
- "src/**"
- "includes/**"
- "tests/**"
- "composer.json"
- ".github/workflows/static-analysis.yml"
- 'src/**'
- 'includes/**'
- 'tests/**'
- 'composer.json'
- '.github/workflows/static-analysis.yml'
branches:
- "master"

Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ name: Test
on: # yamllint disable-line rule:truthy
pull_request:
paths:
- "src/**"
- "includes/**"
- "tests/**"
- "composer.json"
- ".github/workflows/test.yaml"
- 'src/**'
- 'includes/**'
- 'tests/**'
- 'composer.json'
- '.github/workflows/test.yaml'
push:
paths:
- "src/**"
- "includes/**"
- "tests/**"
- "composer.json"
- ".github/workflows/test.yaml"
- 'src/**'
- 'includes/**'
- 'tests/**'
- 'composer.json'
- '.github/workflows/test.yaml'
branches:
- "master"

Expand Down
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wpbrowser.wptestkit.dev
53 changes: 53 additions & 0 deletions docs/modules/WPDb.md
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,16 @@ $I->dontSeeSiteOptionInDatabase('foo_count', 23);
$I->dontSeeSiteOptionInDatabase(['option_name => 'foo_count', 'option_value' => 23]);
```

#### dontSeeSiteTransientInDatabase
Signature: `dontSeeSiteTransientInDatabase(string $transient, [mixed $value])` : `void`

Checks that a site transient is not in the database.

```php
<?php
$I->dontSeeSiteTransientInDatabase('foo');
$I->dontSeeSiteTransientInDatabase('foo', 23);
```
#### dontSeeTableInDatabase
Signature: `dontSeeTableInDatabase(string $table)` : `void`

Expand Down Expand Up @@ -615,6 +625,16 @@ list($termId, $termTaxonomyId) = $I->haveTermInDatabase('fiction', 'genre');
$I->dontSeeTermTaxonomyInDatabase(['term_id' => $termId, 'taxonomy' => 'country']);
```

#### dontSeeTransientInDatabase
Signature: `dontSeeTransientInDatabase(string $transient, [mixed $value])` : `void`

Checks that a transient is not in the database.

```php
<?php
$I->dontSeeTransientInDatabase('foo');
$I->dontSeeTransientInDatabase('foo', 23);
```
#### dontSeeUserInDatabase
Signature: `dontSeeUserInDatabase(array $criteria)` : `void`

Expand Down Expand Up @@ -1200,6 +1220,17 @@ $I->useBlog(23);
$I->grabTermsTableName();
```

#### grabTransientFromDatabase
Signature: `grabTransientFromDatabase(string $transient)` : `mixed`

Fetches the value of a transient from the database.

```php
<?php
$I->haveTransientInDatabase('foo', 23);
$transientValue = $I->grabTransientFromDatabase('foo');
$I->assertEquals(23, $transientValue);
```
#### grabUserIdFromDatabase
Signature: `grabUserIdFromDatabase(string $userLogin)` : `int|false`

Expand Down Expand Up @@ -1932,6 +1963,17 @@ $I->seeSiteSiteTransientInDatabase('total_counts');
$I->seeSiteSiteTransientInDatabase('total_counts', 23);
```

#### seeSiteTransientInDatabase
Signature: `seeSiteTransientInDatabase(string $transient, [mixed $value])` : `void`

Checks that a site transient is in the database.

```php
<?php
$I->haveSiteTransientInDatabase('foo', 23);
$I->seeSiteTransientInDatabase('foo');
$I->seeSiteTransientInDatabase('foo', 23);
```
#### seeTableInDatabase
Signature: `seeTableInDatabase(string $table)` : `void`

Expand Down Expand Up @@ -1989,6 +2031,17 @@ list($termId, $termTaxonomyId) = $I->haveTermInDatabase('fiction', 'genre');
$I->seeTermTaxonomyInDatabase(['term_id' => $termId, 'taxonomy' => 'genre']);
```

#### seeTransientInDatabase
Signature: `seeTransientInDatabase(string $name, [mixed $value])` : `void`

Checks that a transient is in the database.

```php
<?php
$I->haveTransientInDatabase('foo', 23);
$I->seeTransientInDatabase('foo');
$I->seeTransientInDatabase('foo', 23);
```
#### seeUserInDatabase
Signature: `seeUserInDatabase(array $criteria)` : `void`

Expand Down
113 changes: 113 additions & 0 deletions src/Module/WPDb.php
Original file line number Diff line number Diff line change
Expand Up @@ -4792,4 +4792,117 @@ protected function normalizeOptionCriteria(array|string $criteriaOrName, mixed $

return $criteria;
}

/**
* Fetches the value of a transient from the database.
*
* @example
* ```php
* $I->haveTransientInDatabase('foo', 23);
* $transientValue = $I->grabTransientFromDatabase('foo');
* $I->assertEquals(23, $transientValue);
* ```
* @param string $transient The transient name.
*
* @return mixed The transient value; it will be unserialized if it was serialized.
*
*/
public function grabTransientFromDatabase(string $transient): mixed
{
$transient = $this->normalizePrefixedOptionName($transient, '_transient_');
return $this->grabOptionFromDatabase($transient);
}

/**
* Checks that a transient is not in the database.
*
* @example
* ```php
* $I->dontSeeTransientInDatabase('foo');
* $I->dontSeeTransientInDatabase('foo', 23);
* ```
* @param mixed $value The optional value to try and match.
*
* @param string $transient The transient name.
* @return void
* @throws JsonException
*
*/
public function dontSeeTransientInDatabase(string $transient, mixed $value = null): void
{
$transient = $this->normalizePrefixedOptionName($transient, '_transient_');
$this->dontSeeOptionInDatabase($transient, $value);
}

/**
* Checks that a transient is in the database.
*
* @example
* ```php
* $I->haveTransientInDatabase('foo', 23);
* $I->seeTransientInDatabase('foo');
* $I->seeTransientInDatabase('foo', 23);
* ```
* @param mixed $value The optional value to try and match.
*
* @param string $name The transient name.
* @return void
* @throws JsonException
*
*/
public function seeTransientInDatabase(string $name, mixed $value = null): void
{
$transient = $this->normalizePrefixedOptionName($name, '_transient_');
$this->seeOptionInDatabase($transient, $value);
}

/**
* Checks that a site transient is not in the database.
*
* @example
* ```php
* $I->dontSeeSiteTransientInDatabase('foo');
* $I->dontSeeSiteTransientInDatabase('foo', 23);
* ```
* @param mixed|null $value The optional value to try and match.
*
* @param string $transient The transient name.
* @return void
*
* @throws JsonException|ModuleException
*
*/
public function dontSeeSiteTransientInDatabase(string $transient, mixed $value = null): void
{
$currentBlogId = $this->blogId;
$this->useMainBlog();
$transient = $this->normalizePrefixedOptionName($transient, '_site_transient_');
$this->dontSeeOptionInDatabase($transient, $value);
$this->useBlog($currentBlogId);
}

/**
* Checks that a site transient is in the database.
*
* @example
* ```php
* $I->haveSiteTransientInDatabase('foo', 23);
* $I->seeSiteTransientInDatabase('foo');
* $I->seeSiteTransientInDatabase('foo', 23);
* ```
* @param mixed|null $value The optional value to try and match.
*
* @param string $transient The transient name.
* @return void
* @throws JsonException|ModuleException
*
*/
public function seeSiteTransientInDatabase(string $transient, mixed $value = null): void
{
$currentBlogId = $this->blogId;
$this->useMainBlog();
$transient = $this->normalizePrefixedOptionName($transient, '_site_transient_');
$this->seeOptionInDatabase($transient, $value);
$this->useBlog($currentBlogId);
}
}
Loading
Loading