Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
DBDiff/tests/Unit/PgDumpCommandTest.php at master · DBDiff/DBDiff · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
DBDiff
DBDiff
Repository navigation
Code
Issues
3
(3)
Pull requests
1
(1)
Actions
Security and quality
Insights
More
items
Files
Expand file tree
master
Breadcrumbs
DBDiff
/
tests
/
Unit
/
PgDumpCommandTest.php
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
117 lines (100 loc) · 4.04 KB
master
Breadcrumbs
DBDiff
/
tests
/
Unit
/
PgDumpCommandTest.php
Copy path
Top
File metadata and controls
Code
Blame
117 lines (100 loc) · 4.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<?php
namespace
Tests
\
Unit
;
use
DBDiff
\
DB
\
Support
\
PgDumpRenderer
;
use
Illuminate
\
Database
\
Connection
;
use
PHPUnit
\
Framework
\
TestCase
;
use
ReflectionMethod
;
/**
* The pg_dump invocation the renderer builds.
*
* Issue #220 narrowed the dump to the schema being diffed. That is a
* performance property and nothing else: pg_dump issues a query per function,
* so dumping a whole Supabase database charged a round trip for every function
* in auth, storage, realtime and the rest — schemas DBDiff never reads. The
* rendered SQL is byte-identical either way, because the table of contents is
* filtered by schema when it is read, so no output test would fail if the flag
* were dropped and the cost would come back unnoticed. Hence these.
*
* No database and no pg_dump binary are needed: the command is assembled from
* connection config, so it can be asserted on directly.
*/
class
PgDumpCommandTest
extends
TestCase
{
/**
* @param array<string, string> $overrides
* @return list<string>
*/
private
function
command
(
array
$
overrides
= [],
string
$
archive
=
'
/tmp/archive
'
):
array
{
$
connection
=
new
Connection
(
static
fn
() =>
null
,
$
overrides
[
'
database
'
] ??
'
thedb
'
,
''
,
array_merge
([
'
driver
'
=>
'
pgsql
'
,
'
host
'
=>
'
db.example.invalid
'
,
'
port
'
=>
'
5432
'
,
'
database
'
=>
'
thedb
'
,
'
username
'
=>
'
someone
'
,
'
password
'
=>
'
secret
'
,
'
schema
'
=>
'
public
'
,
],
$
overrides
)
);
$
method
=
new
ReflectionMethod
(PgDumpRenderer::class,
'
dumpCommand
'
);
$
method
->
setAccessible
(
true
);
/** @var list<string> $command */
$
command
=
$
method
->
invoke
(
null
,
$
connection
,
$
archive
);
return
$
command
;
}
public
function
testTheDumpIsNarrowedToOneSchema
():
void
{
$
this
->
assertContains
(
'
--schema=public
'
,
$
this
->
command
());
}
public
function
testItNarrowsToTheConfiguredSchema
():
void
{
// renderFor() reads the TOC with this same config value, so the dump
// and the filter cannot disagree about which schema is being diffed.
$
this
->
assertContains
(
'
--schema=reporting
'
,
$
this
->
command
([
'
schema
'
=>
'
reporting
'
]));
}
public
function
testAnAbsentSchemaFallsBackToPublic
():
void
{
$
this
->
assertContains
(
'
--schema=public
'
,
$
this
->
command
([
'
schema
'
=>
''
]));
}
public
function
testItDumpsStructureOnlyInTheCustomFormat
():
void
{
$
command
=
$
this
->
command
();
// --schema-only: this renders DDL, and the data diff is a separate
// path. --format=custom: pg_restore -L needs an archive to select
// single objects out of, which a plain SQL dump cannot provide.
$
this
->
assertContains
(
'
--schema-only
'
,
$
command
);
$
this
->
assertContains
(
'
--format=custom
'
,
$
command
);
}
public
function
testTheArchivePathIsPassedAsGiven
():
void
{
$
this
->
assertContains
(
'
--file=/tmp/somewhere-else
'
,
$
this
->
command
([],
'
/tmp/somewhere-else
'
));
}
public
function
testThePasswordNeverReachesTheCommandLine
():
void
{
// It travels in the environment instead, where `ps` cannot read it.
foreach
(
$
this
->
command
()
as
$
argument
) {
$
this
->
assertStringNotContainsString
(
'
secret
'
,
$
argument
);
}
}
public
function
testTheConnectionIsAddressedAsAUrl
():
void
{
$
command
=
$
this
->
command
();
$
this
->
assertContains
(
'
--dbname=postgresql://someone@db.example.invalid:5432/thedb
'
,
$
command
);
}
public
function
testPgDumpIsTheFirstArgument
():
void
{
// And is overridable, so a pinned client can be used against an older
// server without changing PATH.
$
this
->
assertSame
(
'
pg_dump
'
,
$
this
->
command
()[
0
]);
}
public
function
testNothingElseIsPassed
():
void
{
// A dump that quietly grows a flag is a dump whose cost or output has
// changed. Six arguments, no more.
$
this
->
assertCount
(
6
,
$
this
->
command
());
}
}
You can’t perform that action at this time.