Skip to content

Commit a443016

Browse files
committed
Added tests for varbinary
1 parent 4637301 commit a443016

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

tests/blog_mysql.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,17 @@ CREATE TABLE `products` (
133133
INSERT INTO `products` (`id`, `name`, `price`, `properties`, `created_at`) VALUES
134134
(1, 'Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01');
135135

136+
DROP TABLE IF EXISTS `barcodes`;
137+
CREATE TABLE `barcodes` (
138+
`id` int(11) NOT NULL AUTO_INCREMENT,
139+
`product_id` int(11) NOT NULL,
140+
`hex` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
141+
`bin` varbinary(255) NOT NULL,
142+
PRIMARY KEY (`id`),
143+
CONSTRAINT `barcodes_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`)
144+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
145+
146+
INSERT INTO `barcodes` (`id`, `product_id`, `hex`, `bin`) VALUES
147+
(1, 1, '00ff01', UNHEX('00ff01'));
148+
136149
-- 2016-11-05 13:11:47

tests/blog_postgresql.sql

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ DROP TABLE IF EXISTS countries CASCADE;
2828
DROP TABLE IF EXISTS events CASCADE;
2929
DROP VIEW IF EXISTS tag_usage;
3030
DROP TABLE IF EXISTS products CASCADE;
31+
DROP TABLE IF EXISTS barcodes CASCADE;
3132

3233
--
3334
-- Enables the Postgis extension
@@ -141,6 +142,17 @@ CREATE TABLE products (
141142
deleted_at timestamp NULL
142143
);
143144

145+
--
146+
-- Name: barcodes; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
147+
--
148+
149+
CREATE TABLE barcodes (
150+
id serial NOT NULL,
151+
product_id integer NOT NULL,
152+
hex character varying(255) NOT NULL,
153+
bin bytea NOT NULL
154+
);
155+
144156
--
145157
-- Data for Name: categories; Type: TABLE DATA; Schema: public; Owner: postgres
146158
--
@@ -209,12 +221,19 @@ INSERT INTO "events" ("name", "datetime", "visitors") VALUES
209221
('Launch', '2016-01-01 13:01:01', 0);
210222

211223
--
212-
-- Data for Name: events; Type: TABLE DATA; Schema: public; Owner: postgres
224+
-- Data for Name: products; Type: TABLE DATA; Schema: public; Owner: postgres
213225
--
214226

215227
INSERT INTO "products" ("name", "price", "properties", "created_at") VALUES
216228
('Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01');
217229

230+
--
231+
-- Data for Name: barcodes; Type: TABLE DATA; Schema: public; Owner: postgres
232+
--
233+
234+
INSERT INTO "barcodes" ("product_id", "hex", "bin") VALUES
235+
(1, '00ff01', E'\\x00ff01');
236+
218237
--
219238
-- Name: categories_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
220239
--
@@ -294,6 +313,14 @@ ALTER TABLE ONLY products
294313
ADD CONSTRAINT products_pkey PRIMARY KEY (id);
295314

296315

316+
--
317+
-- Name: barcodes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
318+
--
319+
320+
ALTER TABLE ONLY barcodes
321+
ADD CONSTRAINT barcodes_pkey PRIMARY KEY (id);
322+
323+
297324
--
298325
-- Name: comments_post_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
299326
--
@@ -329,6 +356,13 @@ CREATE INDEX posts_category_id_idx ON posts USING btree (category_id);
329356
CREATE INDEX posts_user_id_idx ON posts USING btree (user_id);
330357

331358

359+
--
360+
-- Name: barcodes_product_id_idx; Type: INDEX; Schema: public; Owner: postgres; Tablespace:
361+
--
362+
363+
CREATE INDEX barcodes_product_id_idx ON barcodes USING btree (product_id);
364+
365+
332366
--
333367
-- Name: comments_post_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
334368
--
@@ -369,6 +403,14 @@ ALTER TABLE ONLY posts
369403
ADD CONSTRAINT posts_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id);
370404

371405

406+
--
407+
-- Name: barcodes_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
408+
--
409+
410+
ALTER TABLE ONLY barcodes
411+
ADD CONSTRAINT barcodes_product_id_fkey FOREIGN KEY (product_id) REFERENCES products(id);
412+
413+
372414
--
373415
-- PostgreSQL database dump complete
374416
--

tests/blog_sqlite.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ CREATE TABLE `products` (
111111
`deleted_at` datetime NULL
112112
);
113113

114-
INSERT INTO `products` (`id`, `name`, `price`, `properties`, `created_at`) VALUES (1, 'Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01');
114+
INSERT INTO `products` (`id`, `name`, `price`, `properties`, `created_at`) VALUES (1, 'Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01');
115+
116+
DROP TABLE IF EXISTS `barcodes`;
117+
CREATE TABLE `barcodes` (
118+
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT,
119+
`product_id` integer NOT NULL,
120+
`hex` text(255) NOT NULL,
121+
`bin` binary(255) NOT NULL
122+
);
123+
124+
INSERT INTO `barcodes` (`id`, `product_id`, `hex`, `bin`) VALUES (1, 1, '00ff01', 'AP8B');
115125

116126
--

tests/blog_sqlserver.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
IF (OBJECT_ID('FK_barcodes_products', 'F') IS NOT NULL)
2+
BEGIN
3+
ALTER TABLE [barcodes] DROP CONSTRAINT [FK_barcodes_products]
4+
END
5+
GO
16
IF (OBJECT_ID('FK_posts_users', 'F') IS NOT NULL)
27
BEGIN
38
ALTER TABLE [posts] DROP CONSTRAINT [FK_posts_users]
@@ -23,6 +28,11 @@ BEGIN
2328
ALTER TABLE [comments] DROP CONSTRAINT [FK_comments_posts]
2429
END
2530
GO
31+
IF (OBJECT_ID('barcodes', 'U') IS NOT NULL)
32+
BEGIN
33+
DROP TABLE [barcodes]
34+
END
35+
GO
2636
IF (OBJECT_ID('products', 'U') IS NOT NULL)
2737
BEGIN
2838
DROP TABLE [products]
@@ -216,6 +226,22 @@ CREATE TABLE [products](
216226
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
217227
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
218228

229+
GO
230+
SET ANSI_NULLS ON
231+
GO
232+
SET QUOTED_IDENTIFIER ON
233+
GO
234+
CREATE TABLE [barcodes](
235+
[id] [int] IDENTITY,
236+
[product_id] [int] NOT NULL,
237+
[hex] [nvarchar](max) NOT NULL,
238+
[bin] [varbinary](max) NOT NULL,
239+
CONSTRAINT [PK_barcodes] PRIMARY KEY CLUSTERED
240+
(
241+
[id] ASC
242+
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
243+
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
244+
219245
GO
220246
SET IDENTITY_INSERT [categories] ON
221247
GO
@@ -293,6 +319,12 @@ INSERT [products] ([id], [name], [price], [properties], [created_at]) VALUES (1,
293319
GO
294320
SET IDENTITY_INSERT [products] OFF
295321
GO
322+
SET IDENTITY_INSERT [barcodes] ON
323+
GO
324+
INSERT [barcodes] ([id], [product_id], [hex], [bin]) VALUES (1, 1, N'00ff01', 0x00ff01)
325+
GO
326+
SET IDENTITY_INSERT [barcodes] OFF
327+
GO
296328
ALTER TABLE [comments] WITH CHECK ADD CONSTRAINT [FK_comments_posts] FOREIGN KEY([post_id])
297329
REFERENCES [posts] ([id])
298330
GO
@@ -318,3 +350,8 @@ REFERENCES [users] ([id])
318350
GO
319351
ALTER TABLE [posts] CHECK CONSTRAINT [FK_posts_users]
320352
GO
353+
ALTER TABLE [barcodes] WITH CHECK ADD CONSTRAINT [FK_barcodes_products] FOREIGN KEY([product_id])
354+
REFERENCES [products] ([id])
355+
GO
356+
ALTER TABLE [barcodes] CHECK CONSTRAINT [FK_barcodes_products]
357+
GO

tests/tests.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,4 +799,11 @@ public function testSoftDeleteProducts()
799799
$test->get('/products?columns=id,deleted_at');
800800
$test->expect('{"products":{"columns":["id","deleted_at"],"records":[[1,"2013-12-11 11:10:09"],[2,"2013-12-11 11:10:09"]]}}');
801801
}
802+
803+
public function testVarBinaryBarcodes()
804+
{
805+
$test = new API($this);
806+
$test->get('/barcodes?transform=1');
807+
$test->expect('{"barcodes":[{"id":1,"product_id":1,"hex":"00ff01","bin":"AP8B"}]}');
808+
}
802809
}

0 commit comments

Comments
 (0)