JsonManipulatorTest.php 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Json;
  12. use Composer\Json\JsonManipulator;
  13. use Composer\Test\TestCase;
  14. class JsonManipulatorTest extends TestCase
  15. {
  16. /**
  17. * @dataProvider linkProvider
  18. */
  19. public function testAddLink($json, $type, $package, $constraint, $expected)
  20. {
  21. $manipulator = new JsonManipulator($json);
  22. $this->assertTrue($manipulator->addLink($type, $package, $constraint));
  23. $this->assertEquals($expected, $manipulator->getContents());
  24. }
  25. public function linkProvider()
  26. {
  27. return array(
  28. array(
  29. '{}',
  30. 'require',
  31. 'vendor/baz',
  32. 'qux',
  33. "{\n".
  34. " \"require\": {\n".
  35. " \"vendor/baz\": \"qux\"\n".
  36. " }\n".
  37. "}\n",
  38. ),
  39. array(
  40. '{
  41. "foo": "bar"
  42. }',
  43. 'require',
  44. 'vendor/baz',
  45. 'qux',
  46. '{
  47. "foo": "bar",
  48. "require": {
  49. "vendor/baz": "qux"
  50. }
  51. }
  52. ',
  53. ),
  54. array(
  55. '{
  56. "require": {
  57. }
  58. }',
  59. 'require',
  60. 'vendor/baz',
  61. 'qux',
  62. '{
  63. "require": {
  64. "vendor/baz": "qux"
  65. }
  66. }
  67. ',
  68. ),
  69. array(
  70. '{
  71. "empty": "",
  72. "require": {
  73. "foo": "bar"
  74. }
  75. }',
  76. 'require',
  77. 'vendor/baz',
  78. 'qux',
  79. '{
  80. "empty": "",
  81. "require": {
  82. "foo": "bar",
  83. "vendor/baz": "qux"
  84. }
  85. }
  86. ',
  87. ),
  88. array(
  89. '{
  90. "require":
  91. {
  92. "foo": "bar",
  93. "vendor/baz": "baz"
  94. }
  95. }',
  96. 'require',
  97. 'vendor/baz',
  98. 'qux',
  99. '{
  100. "require":
  101. {
  102. "foo": "bar",
  103. "vendor/baz": "qux"
  104. }
  105. }
  106. ',
  107. ),
  108. array(
  109. '{
  110. "require":
  111. {
  112. "foo": "bar",
  113. "vendor/baz": "baz"
  114. }
  115. }',
  116. 'require',
  117. 'vEnDoR/bAz',
  118. 'qux',
  119. '{
  120. "require":
  121. {
  122. "foo": "bar",
  123. "vendor/baz": "qux"
  124. }
  125. }
  126. ',
  127. ),
  128. array(
  129. '{
  130. "require":
  131. {
  132. "foo": "bar",
  133. "vendor\/baz": "baz"
  134. }
  135. }',
  136. 'require',
  137. 'vendor/baz',
  138. 'qux',
  139. '{
  140. "require":
  141. {
  142. "foo": "bar",
  143. "vendor/baz": "qux"
  144. }
  145. }
  146. ',
  147. ),
  148. array(
  149. '{
  150. "require":
  151. {
  152. "foo": "bar",
  153. "vendor\/baz": "baz"
  154. }
  155. }',
  156. 'require',
  157. 'vEnDoR/bAz',
  158. 'qux',
  159. '{
  160. "require":
  161. {
  162. "foo": "bar",
  163. "vendor/baz": "qux"
  164. }
  165. }
  166. ',
  167. ),
  168. array(
  169. '{
  170. "require": {
  171. "foo": "bar"
  172. },
  173. "repositories": [{
  174. "type": "package",
  175. "package": {
  176. "require": {
  177. "foo": "bar"
  178. }
  179. }
  180. }]
  181. }',
  182. 'require',
  183. 'foo',
  184. 'qux',
  185. '{
  186. "require": {
  187. "foo": "qux"
  188. },
  189. "repositories": [{
  190. "type": "package",
  191. "package": {
  192. "require": {
  193. "foo": "bar"
  194. }
  195. }
  196. }]
  197. }
  198. ',
  199. ),
  200. array(
  201. '{
  202. "repositories": [{
  203. "type": "package",
  204. "package": {
  205. "require": {
  206. "foo": "bar"
  207. }
  208. }
  209. }]
  210. }',
  211. 'require',
  212. 'foo',
  213. 'qux',
  214. '{
  215. "repositories": [{
  216. "type": "package",
  217. "package": {
  218. "require": {
  219. "foo": "bar"
  220. }
  221. }
  222. }],
  223. "require": {
  224. "foo": "qux"
  225. }
  226. }
  227. ',
  228. ),
  229. array(
  230. '{
  231. "require": {
  232. "php": "5.*"
  233. }
  234. }',
  235. 'require-dev',
  236. 'foo',
  237. 'qux',
  238. '{
  239. "require": {
  240. "php": "5.*"
  241. },
  242. "require-dev": {
  243. "foo": "qux"
  244. }
  245. }
  246. ',
  247. ),
  248. array(
  249. '{
  250. "require": {
  251. "php": "5.*"
  252. },
  253. "require-dev": {
  254. "foo": "bar"
  255. }
  256. }',
  257. 'require-dev',
  258. 'foo',
  259. 'qux',
  260. '{
  261. "require": {
  262. "php": "5.*"
  263. },
  264. "require-dev": {
  265. "foo": "qux"
  266. }
  267. }
  268. ',
  269. ),
  270. array(
  271. '{
  272. "repositories": [{
  273. "type": "package",
  274. "package": {
  275. "bar": "ba[z",
  276. "dist": {
  277. "url": "http...",
  278. "type": "zip"
  279. },
  280. "autoload": {
  281. "classmap": [ "foo/bar" ]
  282. }
  283. }
  284. }],
  285. "require": {
  286. "php": "5.*"
  287. },
  288. "require-dev": {
  289. "foo": "bar"
  290. }
  291. }',
  292. 'require-dev',
  293. 'foo',
  294. 'qux',
  295. '{
  296. "repositories": [{
  297. "type": "package",
  298. "package": {
  299. "bar": "ba[z",
  300. "dist": {
  301. "url": "http...",
  302. "type": "zip"
  303. },
  304. "autoload": {
  305. "classmap": [ "foo/bar" ]
  306. }
  307. }
  308. }],
  309. "require": {
  310. "php": "5.*"
  311. },
  312. "require-dev": {
  313. "foo": "qux"
  314. }
  315. }
  316. ',
  317. ),
  318. array(
  319. '{
  320. "config": {
  321. "cache-files-ttl": 0,
  322. "discard-changes": true
  323. },
  324. "minimum-stability": "stable",
  325. "prefer-stable": false,
  326. "provide": {
  327. "heroku-sys/cedar": "14.2016.03.22"
  328. },
  329. "repositories": [
  330. {
  331. "packagist.org": false
  332. },
  333. {
  334. "type": "package",
  335. "package": [
  336. {
  337. "type": "metapackage",
  338. "name": "anthonymartin/geo-location",
  339. "version": "v1.0.0",
  340. "require": {
  341. "heroku-sys/php": ">=5.3.0"
  342. },
  343. "replace": [],
  344. "provide": [],
  345. "conflict": []
  346. },
  347. {
  348. "type": "metapackage",
  349. "name": "aws/aws-sdk-php",
  350. "version": "3.9.4",
  351. "require": {
  352. "heroku-sys/php": ">=5.5"
  353. },
  354. "replace": [],
  355. "provide": [],
  356. "conflict": []
  357. },
  358. {
  359. "type": "metapackage",
  360. "name": "cloudinary/cloudinary_php",
  361. "version": "dev-master",
  362. "require": {
  363. "heroku-sys/ext-curl": "*",
  364. "heroku-sys/ext-json": "*",
  365. "heroku-sys/php": ">=5.3.0"
  366. },
  367. "replace": [],
  368. "provide": [],
  369. "conflict": []
  370. },
  371. {
  372. "type": "metapackage",
  373. "name": "doctrine/annotations",
  374. "version": "v1.2.7",
  375. "require": {
  376. "heroku-sys/php": ">=5.3.2"
  377. },
  378. "replace": [],
  379. "provide": [],
  380. "conflict": []
  381. },
  382. {
  383. "type": "metapackage",
  384. "name": "doctrine/cache",
  385. "version": "v1.6.0",
  386. "require": {
  387. "heroku-sys/php": "~5.5|~7.0"
  388. },
  389. "replace": [],
  390. "provide": [],
  391. "conflict": []
  392. },
  393. {
  394. "type": "metapackage",
  395. "name": "doctrine/collections",
  396. "version": "v1.3.0",
  397. "require": {
  398. "heroku-sys/php": ">=5.3.2"
  399. },
  400. "replace": [],
  401. "provide": [],
  402. "conflict": []
  403. },
  404. {
  405. "type": "metapackage",
  406. "name": "doctrine/common",
  407. "version": "v2.6.1",
  408. "require": {
  409. "heroku-sys/php": "~5.5|~7.0"
  410. },
  411. "replace": [],
  412. "provide": [],
  413. "conflict": []
  414. },
  415. {
  416. "type": "metapackage",
  417. "name": "doctrine/inflector",
  418. "version": "v1.1.0",
  419. "require": {
  420. "heroku-sys/php": ">=5.3.2"
  421. },
  422. "replace": [],
  423. "provide": [],
  424. "conflict": []
  425. },
  426. {
  427. "type": "metapackage",
  428. "name": "doctrine/lexer",
  429. "version": "v1.0.1",
  430. "require": {
  431. "heroku-sys/php": ">=5.3.2"
  432. },
  433. "replace": [],
  434. "provide": [],
  435. "conflict": []
  436. },
  437. {
  438. "type": "metapackage",
  439. "name": "geoip/geoip",
  440. "version": "v1.16",
  441. "require": [],
  442. "replace": [],
  443. "provide": [],
  444. "conflict": {
  445. "heroku-sys/ext-geoip": "*"
  446. }
  447. },
  448. {
  449. "type": "metapackage",
  450. "name": "giggsey/libphonenumber-for-php",
  451. "version": "7.2.5",
  452. "require": {
  453. "heroku-sys/ext-mbstring": "*"
  454. },
  455. "replace": [],
  456. "provide": [],
  457. "conflict": []
  458. },
  459. {
  460. "type": "metapackage",
  461. "name": "guzzlehttp/guzzle",
  462. "version": "5.3.0",
  463. "require": {
  464. "heroku-sys/php": ">=5.4.0"
  465. },
  466. "replace": [],
  467. "provide": [],
  468. "conflict": []
  469. },
  470. {
  471. "type": "metapackage",
  472. "name": "guzzlehttp/promises",
  473. "version": "1.0.3",
  474. "require": {
  475. "heroku-sys/php": ">=5.5.0"
  476. },
  477. "replace": [],
  478. "provide": [],
  479. "conflict": []
  480. },
  481. {
  482. "type": "metapackage",
  483. "name": "guzzlehttp/psr7",
  484. "version": "1.2.3",
  485. "require": {
  486. "heroku-sys/php": ">=5.4.0"
  487. },
  488. "replace": [],
  489. "provide": [],
  490. "conflict": []
  491. },
  492. {
  493. "type": "metapackage",
  494. "name": "guzzlehttp/ringphp",
  495. "version": "1.1.0",
  496. "require": {
  497. "heroku-sys/php": ">=5.4.0"
  498. },
  499. "replace": [],
  500. "provide": [],
  501. "conflict": []
  502. },
  503. {
  504. "type": "metapackage",
  505. "name": "guzzlehttp/streams",
  506. "version": "3.0.0",
  507. "require": {
  508. "heroku-sys/php": ">=5.4.0"
  509. },
  510. "replace": [],
  511. "provide": [],
  512. "conflict": []
  513. },
  514. {
  515. "type": "metapackage",
  516. "name": "hipchat/hipchat-php",
  517. "version": "v1.4",
  518. "require": {
  519. "heroku-sys/php": ">=5.3.0"
  520. },
  521. "replace": [],
  522. "provide": [],
  523. "conflict": []
  524. },
  525. {
  526. "type": "metapackage",
  527. "name": "kriswallsmith/buzz",
  528. "version": "v0.15",
  529. "require": {
  530. "heroku-sys/php": ">=5.3.0"
  531. },
  532. "replace": [],
  533. "provide": [],
  534. "conflict": []
  535. },
  536. {
  537. "type": "metapackage",
  538. "name": "league/csv",
  539. "version": "8.0.0",
  540. "require": {
  541. "heroku-sys/ext-mbstring": "*",
  542. "heroku-sys/php": ">=5.5.0"
  543. },
  544. "replace": [],
  545. "provide": [],
  546. "conflict": []
  547. },
  548. {
  549. "type": "metapackage",
  550. "name": "league/fractal",
  551. "version": "0.13.0",
  552. "require": {
  553. "heroku-sys/php": ">=5.4"
  554. },
  555. "replace": [],
  556. "provide": [],
  557. "conflict": []
  558. },
  559. {
  560. "type": "metapackage",
  561. "name": "mashape/unirest-php",
  562. "version": "1.2.1",
  563. "require": {
  564. "heroku-sys/ext-curl": "*",
  565. "heroku-sys/ext-json": "*",
  566. "heroku-sys/php": ">=5.3.0"
  567. },
  568. "replace": [],
  569. "provide": [],
  570. "conflict": []
  571. },
  572. {
  573. "type": "metapackage",
  574. "name": "mtdowling/jmespath.php",
  575. "version": "2.3.0",
  576. "require": {
  577. "heroku-sys/php": ">=5.4.0"
  578. },
  579. "replace": [],
  580. "provide": [],
  581. "conflict": []
  582. },
  583. {
  584. "type": "metapackage",
  585. "name": "palex/phpstructureddata",
  586. "version": "v2.0.1",
  587. "require": {
  588. "heroku-sys/php": ">=5.3.0"
  589. },
  590. "replace": [],
  591. "provide": [],
  592. "conflict": []
  593. },
  594. {
  595. "type": "metapackage",
  596. "name": "psr/http-message",
  597. "version": "1.0",
  598. "require": {
  599. "heroku-sys/php": ">=5.3.0"
  600. },
  601. "replace": [],
  602. "provide": [],
  603. "conflict": []
  604. },
  605. {
  606. "type": "metapackage",
  607. "name": "react/promise",
  608. "version": "v2.2.1",
  609. "require": {
  610. "heroku-sys/php": ">=5.4.0"
  611. },
  612. "replace": [],
  613. "provide": [],
  614. "conflict": []
  615. },
  616. {
  617. "type": "metapackage",
  618. "name": "rollbar/rollbar",
  619. "version": "v0.15.0",
  620. "require": {
  621. "heroku-sys/ext-curl": "*"
  622. },
  623. "replace": [],
  624. "provide": [],
  625. "conflict": []
  626. },
  627. {
  628. "type": "metapackage",
  629. "name": "ronanguilloux/isocodes",
  630. "version": "1.2.0",
  631. "require": {
  632. "heroku-sys/ext-bcmath": "*",
  633. "heroku-sys/php": ">=5.4.0"
  634. },
  635. "replace": [],
  636. "provide": [],
  637. "conflict": []
  638. },
  639. {
  640. "type": "metapackage",
  641. "name": "sendgrid/sendgrid",
  642. "version": "2.1.1",
  643. "require": {
  644. "heroku-sys/php": ">=5.3"
  645. },
  646. "replace": [],
  647. "provide": [],
  648. "conflict": []
  649. },
  650. {
  651. "type": "metapackage",
  652. "name": "sendgrid/smtpapi",
  653. "version": "0.0.1",
  654. "require": {
  655. "heroku-sys/php": ">=5.3"
  656. },
  657. "replace": [],
  658. "provide": [],
  659. "conflict": []
  660. },
  661. {
  662. "type": "metapackage",
  663. "name": "symfony/css-selector",
  664. "version": "v2.8.2",
  665. "require": {
  666. "heroku-sys/php": ">=5.3.9"
  667. },
  668. "replace": [],
  669. "provide": [],
  670. "conflict": []
  671. },
  672. {
  673. "type": "metapackage",
  674. "name": "symfony/http-foundation",
  675. "version": "v2.8.2",
  676. "require": {
  677. "heroku-sys/php": ">=5.3.9"
  678. },
  679. "replace": [],
  680. "provide": [],
  681. "conflict": []
  682. },
  683. {
  684. "type": "metapackage",
  685. "name": "symfony/polyfill-php54",
  686. "version": "v1.1.0",
  687. "require": {
  688. "heroku-sys/php": ">=5.3.3"
  689. },
  690. "replace": [],
  691. "provide": [],
  692. "conflict": []
  693. },
  694. {
  695. "type": "metapackage",
  696. "name": "symfony/polyfill-php55",
  697. "version": "v1.1.0",
  698. "require": {
  699. "heroku-sys/php": ">=5.3.3"
  700. },
  701. "replace": [],
  702. "provide": [],
  703. "conflict": []
  704. },
  705. {
  706. "type": "metapackage",
  707. "name": "thepixeldeveloper/sitemap",
  708. "version": "3.0.0",
  709. "require": {
  710. "heroku-sys/php": ">=5.3.0"
  711. },
  712. "replace": [],
  713. "provide": [],
  714. "conflict": []
  715. },
  716. {
  717. "type": "metapackage",
  718. "name": "tijsverkoyen/css-to-inline-styles",
  719. "version": "1.5.5",
  720. "require": {
  721. "heroku-sys/php": ">=5.3.0"
  722. },
  723. "replace": [],
  724. "provide": [],
  725. "conflict": []
  726. },
  727. {
  728. "type": "metapackage",
  729. "name": "yiisoft/yii",
  730. "version": "1.1.17",
  731. "require": {
  732. "heroku-sys/php": ">=5.1.0"
  733. },
  734. "replace": [],
  735. "provide": [],
  736. "conflict": []
  737. },
  738. {
  739. "type": "metapackage",
  740. "name": "composer.json/composer.lock",
  741. "version": "dev-597511d6d51b96e4a8afeba2c79982e5",
  742. "require": {
  743. "heroku-sys/php": "~5.6.0",
  744. "heroku-sys/ext-newrelic": "*",
  745. "heroku-sys/ext-gd": "*",
  746. "heroku-sys/ext-redis": "*"
  747. },
  748. "replace": [],
  749. "provide": [],
  750. "conflict": []
  751. }
  752. ]
  753. }
  754. ],
  755. "require": {
  756. "composer.json/composer.lock": "dev-597511d6d51b96e4a8afeba2c79982e5",
  757. "anthonymartin/geo-location": "v1.0.0",
  758. "aws/aws-sdk-php": "3.9.4",
  759. "cloudinary/cloudinary_php": "dev-master",
  760. "doctrine/annotations": "v1.2.7",
  761. "doctrine/cache": "v1.6.0",
  762. "doctrine/collections": "v1.3.0",
  763. "doctrine/common": "v2.6.1",
  764. "doctrine/inflector": "v1.1.0",
  765. "doctrine/lexer": "v1.0.1",
  766. "geoip/geoip": "v1.16",
  767. "giggsey/libphonenumber-for-php": "7.2.5",
  768. "guzzlehttp/guzzle": "5.3.0",
  769. "guzzlehttp/promises": "1.0.3",
  770. "guzzlehttp/psr7": "1.2.3",
  771. "guzzlehttp/ringphp": "1.1.0",
  772. "guzzlehttp/streams": "3.0.0",
  773. "hipchat/hipchat-php": "v1.4",
  774. "kriswallsmith/buzz": "v0.15",
  775. "league/csv": "8.0.0",
  776. "league/fractal": "0.13.0",
  777. "mashape/unirest-php": "1.2.1",
  778. "mtdowling/jmespath.php": "2.3.0",
  779. "palex/phpstructureddata": "v2.0.1",
  780. "psr/http-message": "1.0",
  781. "react/promise": "v2.2.1",
  782. "rollbar/rollbar": "v0.15.0",
  783. "ronanguilloux/isocodes": "1.2.0",
  784. "sendgrid/sendgrid": "2.1.1",
  785. "sendgrid/smtpapi": "0.0.1",
  786. "symfony/css-selector": "v2.8.2",
  787. "symfony/http-foundation": "v2.8.2",
  788. "symfony/polyfill-php54": "v1.1.0",
  789. "symfony/polyfill-php55": "v1.1.0",
  790. "thepixeldeveloper/sitemap": "3.0.0",
  791. "tijsverkoyen/css-to-inline-styles": "1.5.5",
  792. "yiisoft/yii": "1.1.17",
  793. "heroku-sys/apache": "^2.4.10",
  794. "heroku-sys/nginx": "~1.8.0"
  795. }
  796. }',
  797. 'require',
  798. 'foo',
  799. 'qux',
  800. '{
  801. "config": {
  802. "cache-files-ttl": 0,
  803. "discard-changes": true
  804. },
  805. "minimum-stability": "stable",
  806. "prefer-stable": false,
  807. "provide": {
  808. "heroku-sys/cedar": "14.2016.03.22"
  809. },
  810. "repositories": [
  811. {
  812. "packagist.org": false
  813. },
  814. {
  815. "type": "package",
  816. "package": [
  817. {
  818. "type": "metapackage",
  819. "name": "anthonymartin/geo-location",
  820. "version": "v1.0.0",
  821. "require": {
  822. "heroku-sys/php": ">=5.3.0"
  823. },
  824. "replace": [],
  825. "provide": [],
  826. "conflict": []
  827. },
  828. {
  829. "type": "metapackage",
  830. "name": "aws/aws-sdk-php",
  831. "version": "3.9.4",
  832. "require": {
  833. "heroku-sys/php": ">=5.5"
  834. },
  835. "replace": [],
  836. "provide": [],
  837. "conflict": []
  838. },
  839. {
  840. "type": "metapackage",
  841. "name": "cloudinary/cloudinary_php",
  842. "version": "dev-master",
  843. "require": {
  844. "heroku-sys/ext-curl": "*",
  845. "heroku-sys/ext-json": "*",
  846. "heroku-sys/php": ">=5.3.0"
  847. },
  848. "replace": [],
  849. "provide": [],
  850. "conflict": []
  851. },
  852. {
  853. "type": "metapackage",
  854. "name": "doctrine/annotations",
  855. "version": "v1.2.7",
  856. "require": {
  857. "heroku-sys/php": ">=5.3.2"
  858. },
  859. "replace": [],
  860. "provide": [],
  861. "conflict": []
  862. },
  863. {
  864. "type": "metapackage",
  865. "name": "doctrine/cache",
  866. "version": "v1.6.0",
  867. "require": {
  868. "heroku-sys/php": "~5.5|~7.0"
  869. },
  870. "replace": [],
  871. "provide": [],
  872. "conflict": []
  873. },
  874. {
  875. "type": "metapackage",
  876. "name": "doctrine/collections",
  877. "version": "v1.3.0",
  878. "require": {
  879. "heroku-sys/php": ">=5.3.2"
  880. },
  881. "replace": [],
  882. "provide": [],
  883. "conflict": []
  884. },
  885. {
  886. "type": "metapackage",
  887. "name": "doctrine/common",
  888. "version": "v2.6.1",
  889. "require": {
  890. "heroku-sys/php": "~5.5|~7.0"
  891. },
  892. "replace": [],
  893. "provide": [],
  894. "conflict": []
  895. },
  896. {
  897. "type": "metapackage",
  898. "name": "doctrine/inflector",
  899. "version": "v1.1.0",
  900. "require": {
  901. "heroku-sys/php": ">=5.3.2"
  902. },
  903. "replace": [],
  904. "provide": [],
  905. "conflict": []
  906. },
  907. {
  908. "type": "metapackage",
  909. "name": "doctrine/lexer",
  910. "version": "v1.0.1",
  911. "require": {
  912. "heroku-sys/php": ">=5.3.2"
  913. },
  914. "replace": [],
  915. "provide": [],
  916. "conflict": []
  917. },
  918. {
  919. "type": "metapackage",
  920. "name": "geoip/geoip",
  921. "version": "v1.16",
  922. "require": [],
  923. "replace": [],
  924. "provide": [],
  925. "conflict": {
  926. "heroku-sys/ext-geoip": "*"
  927. }
  928. },
  929. {
  930. "type": "metapackage",
  931. "name": "giggsey/libphonenumber-for-php",
  932. "version": "7.2.5",
  933. "require": {
  934. "heroku-sys/ext-mbstring": "*"
  935. },
  936. "replace": [],
  937. "provide": [],
  938. "conflict": []
  939. },
  940. {
  941. "type": "metapackage",
  942. "name": "guzzlehttp/guzzle",
  943. "version": "5.3.0",
  944. "require": {
  945. "heroku-sys/php": ">=5.4.0"
  946. },
  947. "replace": [],
  948. "provide": [],
  949. "conflict": []
  950. },
  951. {
  952. "type": "metapackage",
  953. "name": "guzzlehttp/promises",
  954. "version": "1.0.3",
  955. "require": {
  956. "heroku-sys/php": ">=5.5.0"
  957. },
  958. "replace": [],
  959. "provide": [],
  960. "conflict": []
  961. },
  962. {
  963. "type": "metapackage",
  964. "name": "guzzlehttp/psr7",
  965. "version": "1.2.3",
  966. "require": {
  967. "heroku-sys/php": ">=5.4.0"
  968. },
  969. "replace": [],
  970. "provide": [],
  971. "conflict": []
  972. },
  973. {
  974. "type": "metapackage",
  975. "name": "guzzlehttp/ringphp",
  976. "version": "1.1.0",
  977. "require": {
  978. "heroku-sys/php": ">=5.4.0"
  979. },
  980. "replace": [],
  981. "provide": [],
  982. "conflict": []
  983. },
  984. {
  985. "type": "metapackage",
  986. "name": "guzzlehttp/streams",
  987. "version": "3.0.0",
  988. "require": {
  989. "heroku-sys/php": ">=5.4.0"
  990. },
  991. "replace": [],
  992. "provide": [],
  993. "conflict": []
  994. },
  995. {
  996. "type": "metapackage",
  997. "name": "hipchat/hipchat-php",
  998. "version": "v1.4",
  999. "require": {
  1000. "heroku-sys/php": ">=5.3.0"
  1001. },
  1002. "replace": [],
  1003. "provide": [],
  1004. "conflict": []
  1005. },
  1006. {
  1007. "type": "metapackage",
  1008. "name": "kriswallsmith/buzz",
  1009. "version": "v0.15",
  1010. "require": {
  1011. "heroku-sys/php": ">=5.3.0"
  1012. },
  1013. "replace": [],
  1014. "provide": [],
  1015. "conflict": []
  1016. },
  1017. {
  1018. "type": "metapackage",
  1019. "name": "league/csv",
  1020. "version": "8.0.0",
  1021. "require": {
  1022. "heroku-sys/ext-mbstring": "*",
  1023. "heroku-sys/php": ">=5.5.0"
  1024. },
  1025. "replace": [],
  1026. "provide": [],
  1027. "conflict": []
  1028. },
  1029. {
  1030. "type": "metapackage",
  1031. "name": "league/fractal",
  1032. "version": "0.13.0",
  1033. "require": {
  1034. "heroku-sys/php": ">=5.4"
  1035. },
  1036. "replace": [],
  1037. "provide": [],
  1038. "conflict": []
  1039. },
  1040. {
  1041. "type": "metapackage",
  1042. "name": "mashape/unirest-php",
  1043. "version": "1.2.1",
  1044. "require": {
  1045. "heroku-sys/ext-curl": "*",
  1046. "heroku-sys/ext-json": "*",
  1047. "heroku-sys/php": ">=5.3.0"
  1048. },
  1049. "replace": [],
  1050. "provide": [],
  1051. "conflict": []
  1052. },
  1053. {
  1054. "type": "metapackage",
  1055. "name": "mtdowling/jmespath.php",
  1056. "version": "2.3.0",
  1057. "require": {
  1058. "heroku-sys/php": ">=5.4.0"
  1059. },
  1060. "replace": [],
  1061. "provide": [],
  1062. "conflict": []
  1063. },
  1064. {
  1065. "type": "metapackage",
  1066. "name": "palex/phpstructureddata",
  1067. "version": "v2.0.1",
  1068. "require": {
  1069. "heroku-sys/php": ">=5.3.0"
  1070. },
  1071. "replace": [],
  1072. "provide": [],
  1073. "conflict": []
  1074. },
  1075. {
  1076. "type": "metapackage",
  1077. "name": "psr/http-message",
  1078. "version": "1.0",
  1079. "require": {
  1080. "heroku-sys/php": ">=5.3.0"
  1081. },
  1082. "replace": [],
  1083. "provide": [],
  1084. "conflict": []
  1085. },
  1086. {
  1087. "type": "metapackage",
  1088. "name": "react/promise",
  1089. "version": "v2.2.1",
  1090. "require": {
  1091. "heroku-sys/php": ">=5.4.0"
  1092. },
  1093. "replace": [],
  1094. "provide": [],
  1095. "conflict": []
  1096. },
  1097. {
  1098. "type": "metapackage",
  1099. "name": "rollbar/rollbar",
  1100. "version": "v0.15.0",
  1101. "require": {
  1102. "heroku-sys/ext-curl": "*"
  1103. },
  1104. "replace": [],
  1105. "provide": [],
  1106. "conflict": []
  1107. },
  1108. {
  1109. "type": "metapackage",
  1110. "name": "ronanguilloux/isocodes",
  1111. "version": "1.2.0",
  1112. "require": {
  1113. "heroku-sys/ext-bcmath": "*",
  1114. "heroku-sys/php": ">=5.4.0"
  1115. },
  1116. "replace": [],
  1117. "provide": [],
  1118. "conflict": []
  1119. },
  1120. {
  1121. "type": "metapackage",
  1122. "name": "sendgrid/sendgrid",
  1123. "version": "2.1.1",
  1124. "require": {
  1125. "heroku-sys/php": ">=5.3"
  1126. },
  1127. "replace": [],
  1128. "provide": [],
  1129. "conflict": []
  1130. },
  1131. {
  1132. "type": "metapackage",
  1133. "name": "sendgrid/smtpapi",
  1134. "version": "0.0.1",
  1135. "require": {
  1136. "heroku-sys/php": ">=5.3"
  1137. },
  1138. "replace": [],
  1139. "provide": [],
  1140. "conflict": []
  1141. },
  1142. {
  1143. "type": "metapackage",
  1144. "name": "symfony/css-selector",
  1145. "version": "v2.8.2",
  1146. "require": {
  1147. "heroku-sys/php": ">=5.3.9"
  1148. },
  1149. "replace": [],
  1150. "provide": [],
  1151. "conflict": []
  1152. },
  1153. {
  1154. "type": "metapackage",
  1155. "name": "symfony/http-foundation",
  1156. "version": "v2.8.2",
  1157. "require": {
  1158. "heroku-sys/php": ">=5.3.9"
  1159. },
  1160. "replace": [],
  1161. "provide": [],
  1162. "conflict": []
  1163. },
  1164. {
  1165. "type": "metapackage",
  1166. "name": "symfony/polyfill-php54",
  1167. "version": "v1.1.0",
  1168. "require": {
  1169. "heroku-sys/php": ">=5.3.3"
  1170. },
  1171. "replace": [],
  1172. "provide": [],
  1173. "conflict": []
  1174. },
  1175. {
  1176. "type": "metapackage",
  1177. "name": "symfony/polyfill-php55",
  1178. "version": "v1.1.0",
  1179. "require": {
  1180. "heroku-sys/php": ">=5.3.3"
  1181. },
  1182. "replace": [],
  1183. "provide": [],
  1184. "conflict": []
  1185. },
  1186. {
  1187. "type": "metapackage",
  1188. "name": "thepixeldeveloper/sitemap",
  1189. "version": "3.0.0",
  1190. "require": {
  1191. "heroku-sys/php": ">=5.3.0"
  1192. },
  1193. "replace": [],
  1194. "provide": [],
  1195. "conflict": []
  1196. },
  1197. {
  1198. "type": "metapackage",
  1199. "name": "tijsverkoyen/css-to-inline-styles",
  1200. "version": "1.5.5",
  1201. "require": {
  1202. "heroku-sys/php": ">=5.3.0"
  1203. },
  1204. "replace": [],
  1205. "provide": [],
  1206. "conflict": []
  1207. },
  1208. {
  1209. "type": "metapackage",
  1210. "name": "yiisoft/yii",
  1211. "version": "1.1.17",
  1212. "require": {
  1213. "heroku-sys/php": ">=5.1.0"
  1214. },
  1215. "replace": [],
  1216. "provide": [],
  1217. "conflict": []
  1218. },
  1219. {
  1220. "type": "metapackage",
  1221. "name": "composer.json/composer.lock",
  1222. "version": "dev-597511d6d51b96e4a8afeba2c79982e5",
  1223. "require": {
  1224. "heroku-sys/php": "~5.6.0",
  1225. "heroku-sys/ext-newrelic": "*",
  1226. "heroku-sys/ext-gd": "*",
  1227. "heroku-sys/ext-redis": "*"
  1228. },
  1229. "replace": [],
  1230. "provide": [],
  1231. "conflict": []
  1232. }
  1233. ]
  1234. }
  1235. ],
  1236. "require": {
  1237. "composer.json/composer.lock": "dev-597511d6d51b96e4a8afeba2c79982e5",
  1238. "anthonymartin/geo-location": "v1.0.0",
  1239. "aws/aws-sdk-php": "3.9.4",
  1240. "cloudinary/cloudinary_php": "dev-master",
  1241. "doctrine/annotations": "v1.2.7",
  1242. "doctrine/cache": "v1.6.0",
  1243. "doctrine/collections": "v1.3.0",
  1244. "doctrine/common": "v2.6.1",
  1245. "doctrine/inflector": "v1.1.0",
  1246. "doctrine/lexer": "v1.0.1",
  1247. "geoip/geoip": "v1.16",
  1248. "giggsey/libphonenumber-for-php": "7.2.5",
  1249. "guzzlehttp/guzzle": "5.3.0",
  1250. "guzzlehttp/promises": "1.0.3",
  1251. "guzzlehttp/psr7": "1.2.3",
  1252. "guzzlehttp/ringphp": "1.1.0",
  1253. "guzzlehttp/streams": "3.0.0",
  1254. "hipchat/hipchat-php": "v1.4",
  1255. "kriswallsmith/buzz": "v0.15",
  1256. "league/csv": "8.0.0",
  1257. "league/fractal": "0.13.0",
  1258. "mashape/unirest-php": "1.2.1",
  1259. "mtdowling/jmespath.php": "2.3.0",
  1260. "palex/phpstructureddata": "v2.0.1",
  1261. "psr/http-message": "1.0",
  1262. "react/promise": "v2.2.1",
  1263. "rollbar/rollbar": "v0.15.0",
  1264. "ronanguilloux/isocodes": "1.2.0",
  1265. "sendgrid/sendgrid": "2.1.1",
  1266. "sendgrid/smtpapi": "0.0.1",
  1267. "symfony/css-selector": "v2.8.2",
  1268. "symfony/http-foundation": "v2.8.2",
  1269. "symfony/polyfill-php54": "v1.1.0",
  1270. "symfony/polyfill-php55": "v1.1.0",
  1271. "thepixeldeveloper/sitemap": "3.0.0",
  1272. "tijsverkoyen/css-to-inline-styles": "1.5.5",
  1273. "yiisoft/yii": "1.1.17",
  1274. "heroku-sys/apache": "^2.4.10",
  1275. "heroku-sys/nginx": "~1.8.0",
  1276. "foo": "qux"
  1277. }
  1278. }
  1279. ',
  1280. ),
  1281. );
  1282. }
  1283. /**
  1284. * @dataProvider providerAddLinkAndSortPackages
  1285. */
  1286. public function testAddLinkAndSortPackages($json, $type, $package, $constraint, $sortPackages, $expected)
  1287. {
  1288. $manipulator = new JsonManipulator($json);
  1289. $this->assertTrue($manipulator->addLink($type, $package, $constraint, $sortPackages));
  1290. $this->assertEquals($expected, $manipulator->getContents());
  1291. }
  1292. public function providerAddLinkAndSortPackages()
  1293. {
  1294. return array(
  1295. array(
  1296. '{
  1297. "require": {
  1298. "vendor/baz": "qux"
  1299. }
  1300. }',
  1301. 'require',
  1302. 'foo',
  1303. 'bar',
  1304. true,
  1305. '{
  1306. "require": {
  1307. "foo": "bar",
  1308. "vendor/baz": "qux"
  1309. }
  1310. }
  1311. ',
  1312. ),
  1313. array(
  1314. '{
  1315. "require": {
  1316. "vendor/baz": "qux"
  1317. }
  1318. }',
  1319. 'require',
  1320. 'foo',
  1321. 'bar',
  1322. false,
  1323. '{
  1324. "require": {
  1325. "vendor/baz": "qux",
  1326. "foo": "bar"
  1327. }
  1328. }
  1329. ',
  1330. ),
  1331. array(
  1332. '{
  1333. "require": {
  1334. "foo": "baz",
  1335. "ext-10gd": "*",
  1336. "ext-2mcrypt": "*",
  1337. "lib-foo": "*",
  1338. "hhvm": "*",
  1339. "php": ">=5.5"
  1340. }
  1341. }',
  1342. 'require',
  1343. 'igorw/retry',
  1344. '*',
  1345. true,
  1346. '{
  1347. "require": {
  1348. "php": ">=5.5",
  1349. "hhvm": "*",
  1350. "ext-2mcrypt": "*",
  1351. "ext-10gd": "*",
  1352. "lib-foo": "*",
  1353. "foo": "baz",
  1354. "igorw/retry": "*"
  1355. }
  1356. }
  1357. ',
  1358. ),
  1359. );
  1360. }
  1361. /**
  1362. * @dataProvider removeSubNodeProvider
  1363. */
  1364. public function testRemoveSubNode($json, $name, $expected, $expectedContent = null)
  1365. {
  1366. $manipulator = new JsonManipulator($json);
  1367. $this->assertEquals($expected, $manipulator->removeSubNode('repositories', $name));
  1368. if (null !== $expectedContent) {
  1369. $this->assertEquals($expectedContent, $manipulator->getContents());
  1370. }
  1371. }
  1372. public function removeSubNodeProvider()
  1373. {
  1374. return array(
  1375. 'works on simple ones first' => array(
  1376. '{
  1377. "repositories": {
  1378. "foo": {
  1379. "foo": "bar",
  1380. "bar": "baz"
  1381. },
  1382. "bar": {
  1383. "foo": "bar",
  1384. "bar": "baz"
  1385. }
  1386. }
  1387. }',
  1388. 'foo',
  1389. true,
  1390. '{
  1391. "repositories": {
  1392. "bar": {
  1393. "foo": "bar",
  1394. "bar": "baz"
  1395. }
  1396. }
  1397. }
  1398. ',
  1399. ),
  1400. 'works on simple ones last' => array(
  1401. '{
  1402. "repositories": {
  1403. "foo": {
  1404. "foo": "bar",
  1405. "bar": "baz"
  1406. },
  1407. "bar": {
  1408. "foo": "bar",
  1409. "bar": "baz"
  1410. }
  1411. }
  1412. }',
  1413. 'bar',
  1414. true,
  1415. '{
  1416. "repositories": {
  1417. "foo": {
  1418. "foo": "bar",
  1419. "bar": "baz"
  1420. }
  1421. }
  1422. }
  1423. ',
  1424. ),
  1425. 'works on simple ones unique' => array(
  1426. '{
  1427. "repositories": {
  1428. "foo": {
  1429. "foo": "bar",
  1430. "bar": "baz"
  1431. }
  1432. }
  1433. }',
  1434. 'foo',
  1435. true,
  1436. '{
  1437. "repositories": {
  1438. }
  1439. }
  1440. ',
  1441. ),
  1442. 'works on simple ones escaped slash' => array(
  1443. '{
  1444. "repositories": {
  1445. "foo\/bar": {
  1446. "bar": "baz"
  1447. }
  1448. }
  1449. }',
  1450. 'foo/bar',
  1451. true,
  1452. '{
  1453. "repositories": {
  1454. }
  1455. }
  1456. ',
  1457. ),
  1458. 'works on simple ones middle' => array(
  1459. '{
  1460. "repositories": {
  1461. "foo": {
  1462. "foo": "bar",
  1463. "bar": "baz"
  1464. },
  1465. "bar": {
  1466. "foo": "bar",
  1467. "bar": "baz"
  1468. },
  1469. "baz": {
  1470. "foo": "bar",
  1471. "bar": "baz"
  1472. }
  1473. }
  1474. }',
  1475. 'bar',
  1476. true,
  1477. '{
  1478. "repositories": {
  1479. "foo": {
  1480. "foo": "bar",
  1481. "bar": "baz"
  1482. },
  1483. "baz": {
  1484. "foo": "bar",
  1485. "bar": "baz"
  1486. }
  1487. }
  1488. }
  1489. ',
  1490. ),
  1491. 'works on undefined ones' => array(
  1492. '{
  1493. "repositories": {
  1494. "main": {
  1495. "foo": "bar",
  1496. "bar": "baz"
  1497. }
  1498. }
  1499. }',
  1500. 'removenotthere',
  1501. true,
  1502. '{
  1503. "repositories": {
  1504. "main": {
  1505. "foo": "bar",
  1506. "bar": "baz"
  1507. }
  1508. }
  1509. }
  1510. ',
  1511. ),
  1512. 'works on child having unmatched name' => array(
  1513. '{
  1514. "repositories": {
  1515. "baz": {
  1516. "foo": "bar",
  1517. "bar": "baz"
  1518. }
  1519. }
  1520. }',
  1521. 'bar',
  1522. true,
  1523. '{
  1524. "repositories": {
  1525. "baz": {
  1526. "foo": "bar",
  1527. "bar": "baz"
  1528. }
  1529. }
  1530. }
  1531. ',
  1532. ),
  1533. 'works on child having duplicate name' => array(
  1534. '{
  1535. "repositories": {
  1536. "foo": {
  1537. "baz": "qux"
  1538. },
  1539. "baz": {
  1540. "foo": "bar",
  1541. "bar": "baz"
  1542. }
  1543. }
  1544. }',
  1545. 'baz',
  1546. true,
  1547. '{
  1548. "repositories": {
  1549. "foo": {
  1550. "baz": "qux"
  1551. }
  1552. }
  1553. }
  1554. ',
  1555. ),
  1556. 'works on empty repos' => array(
  1557. '{
  1558. "repositories": {
  1559. }
  1560. }',
  1561. 'bar',
  1562. true,
  1563. ),
  1564. 'works on empty repos2' => array(
  1565. '{
  1566. "repositories": {}
  1567. }',
  1568. 'bar',
  1569. true,
  1570. ),
  1571. 'works on missing repos' => array(
  1572. "{\n}",
  1573. 'bar',
  1574. true,
  1575. ),
  1576. 'works on deep repos' => array(
  1577. '{
  1578. "repositories": {
  1579. "foo": {
  1580. "package": { "bar": "baz" }
  1581. }
  1582. }
  1583. }',
  1584. 'foo',
  1585. true,
  1586. '{
  1587. "repositories": {
  1588. }
  1589. }
  1590. ',
  1591. ),
  1592. 'works on deep repos with borked texts' => array(
  1593. '{
  1594. "repositories": {
  1595. "foo": {
  1596. "package": { "bar": "ba{z" }
  1597. }
  1598. }
  1599. }',
  1600. 'bar',
  1601. true,
  1602. '{
  1603. "repositories": {
  1604. "foo": {
  1605. "package": { "bar": "ba{z" }
  1606. }
  1607. }
  1608. }
  1609. ',
  1610. '{
  1611. }
  1612. ',
  1613. ),
  1614. 'works on deep repos with borked texts2' => array(
  1615. '{
  1616. "repositories": {
  1617. "foo": {
  1618. "package": { "bar": "ba}z" }
  1619. }
  1620. }
  1621. }',
  1622. 'bar',
  1623. true,
  1624. '{
  1625. "repositories": {
  1626. "foo": {
  1627. "package": { "bar": "ba}z" }
  1628. }
  1629. }
  1630. }
  1631. ',
  1632. '{
  1633. }
  1634. ',
  1635. ),
  1636. 'fails on deep arrays with borked texts' => array(
  1637. '{
  1638. "repositories": [
  1639. {
  1640. "package": { "bar": "ba[z" }
  1641. }
  1642. ]
  1643. }',
  1644. 'bar',
  1645. false,
  1646. ),
  1647. 'fails on deep arrays with borked texts2' => array(
  1648. '{
  1649. "repositories": [
  1650. {
  1651. "package": { "bar": "ba]z" }
  1652. }
  1653. ]
  1654. }',
  1655. 'bar',
  1656. false,
  1657. ),
  1658. );
  1659. }
  1660. public function testRemoveSubNodeFromRequire()
  1661. {
  1662. $manipulator = new JsonManipulator('{
  1663. "repositories": [
  1664. {
  1665. "package": {
  1666. "require": {
  1667. "this/should-not-end-up-in-root-require": "~2.0"
  1668. },
  1669. "require-dev": {
  1670. "this/should-not-end-up-in-root-require-dev": "~2.0"
  1671. }
  1672. }
  1673. }
  1674. ],
  1675. "require": {
  1676. "package/a": "*",
  1677. "package/b": "*",
  1678. "package/c": "*"
  1679. },
  1680. "require-dev": {
  1681. "package/d": "*"
  1682. }
  1683. }');
  1684. $this->assertTrue($manipulator->removeSubNode('require', 'package/c'));
  1685. $this->assertTrue($manipulator->removeSubNode('require-dev', 'package/d'));
  1686. $this->assertEquals('{
  1687. "repositories": [
  1688. {
  1689. "package": {
  1690. "require": {
  1691. "this/should-not-end-up-in-root-require": "~2.0"
  1692. },
  1693. "require-dev": {
  1694. "this/should-not-end-up-in-root-require-dev": "~2.0"
  1695. }
  1696. }
  1697. }
  1698. ],
  1699. "require": {
  1700. "package/a": "*",
  1701. "package/b": "*"
  1702. },
  1703. "require-dev": {
  1704. }
  1705. }
  1706. ', $manipulator->getContents());
  1707. }
  1708. public function testAddSubNodeInRequire()
  1709. {
  1710. $manipulator = new JsonManipulator('{
  1711. "repositories": [
  1712. {
  1713. "package": {
  1714. "require": {
  1715. "this/should-not-end-up-in-root-require": "~2.0"
  1716. },
  1717. "require-dev": {
  1718. "this/should-not-end-up-in-root-require-dev": "~2.0"
  1719. }
  1720. }
  1721. }
  1722. ],
  1723. "require": {
  1724. "package/a": "*",
  1725. "package/b": "*"
  1726. },
  1727. "require-dev": {
  1728. "package/d": "*"
  1729. }
  1730. }');
  1731. $this->assertTrue($manipulator->addSubNode('require', 'package/c', '*'));
  1732. $this->assertTrue($manipulator->addSubNode('require-dev', 'package/e', '*'));
  1733. $this->assertEquals('{
  1734. "repositories": [
  1735. {
  1736. "package": {
  1737. "require": {
  1738. "this/should-not-end-up-in-root-require": "~2.0"
  1739. },
  1740. "require-dev": {
  1741. "this/should-not-end-up-in-root-require-dev": "~2.0"
  1742. }
  1743. }
  1744. }
  1745. ],
  1746. "require": {
  1747. "package/a": "*",
  1748. "package/b": "*",
  1749. "package/c": "*"
  1750. },
  1751. "require-dev": {
  1752. "package/d": "*",
  1753. "package/e": "*"
  1754. }
  1755. }
  1756. ', $manipulator->getContents());
  1757. }
  1758. public function testAddExtraWithPackage()
  1759. {
  1760. //$this->markTestSkipped();
  1761. $manipulator = new JsonManipulator('{
  1762. "repositories": [
  1763. {
  1764. "type": "package",
  1765. "package": {
  1766. "authors": [],
  1767. "extra": {
  1768. "package-xml": "package.xml"
  1769. }
  1770. }
  1771. }
  1772. ],
  1773. "extra": {
  1774. "auto-append-gitignore": true
  1775. }
  1776. }');
  1777. $this->assertTrue($manipulator->addProperty('extra.foo-bar', true));
  1778. $this->assertEquals('{
  1779. "repositories": [
  1780. {
  1781. "type": "package",
  1782. "package": {
  1783. "authors": [],
  1784. "extra": {
  1785. "package-xml": "package.xml"
  1786. }
  1787. }
  1788. }
  1789. ],
  1790. "extra": {
  1791. "auto-append-gitignore": true,
  1792. "foo-bar": true
  1793. }
  1794. }
  1795. ', $manipulator->getContents());
  1796. }
  1797. public function testAddConfigWithPackage() {
  1798. $manipulator = new JsonManipulator('{
  1799. "repositories": [
  1800. {
  1801. "type": "package",
  1802. "package": {
  1803. "authors": [],
  1804. "extra": {
  1805. "package-xml": "package.xml"
  1806. }
  1807. }
  1808. }
  1809. ],
  1810. "config": {
  1811. "platform": {
  1812. "php": "5.3.9"
  1813. }
  1814. }
  1815. }');
  1816. $this->assertTrue($manipulator->addConfigSetting('preferred-install.my-organization/stable-package', 'dist'));
  1817. $this->assertEquals('{
  1818. "repositories": [
  1819. {
  1820. "type": "package",
  1821. "package": {
  1822. "authors": [],
  1823. "extra": {
  1824. "package-xml": "package.xml"
  1825. }
  1826. }
  1827. }
  1828. ],
  1829. "config": {
  1830. "platform": {
  1831. "php": "5.3.9"
  1832. },
  1833. "preferred-install": {
  1834. "my-organization/stable-package": "dist"
  1835. }
  1836. }
  1837. }
  1838. ', $manipulator->getContents());
  1839. }
  1840. public function testAddSuggestWithPackage()
  1841. {
  1842. $manipulator = new JsonManipulator('{
  1843. "repositories": [
  1844. {
  1845. "type": "package",
  1846. "package": {
  1847. "authors": [],
  1848. "extra": {
  1849. "package-xml": "package.xml"
  1850. }
  1851. }
  1852. }
  1853. ],
  1854. "suggest": {
  1855. "package": "Description"
  1856. }
  1857. }');
  1858. $this->assertTrue($manipulator->addProperty('suggest.new-package', 'new-description'));
  1859. $this->assertEquals('{
  1860. "repositories": [
  1861. {
  1862. "type": "package",
  1863. "package": {
  1864. "authors": [],
  1865. "extra": {
  1866. "package-xml": "package.xml"
  1867. }
  1868. }
  1869. }
  1870. ],
  1871. "suggest": {
  1872. "package": "Description",
  1873. "new-package": "new-description"
  1874. }
  1875. }
  1876. ', $manipulator->getContents());
  1877. }
  1878. public function testAddRepositoryCanInitializeEmptyRepositories()
  1879. {
  1880. $manipulator = new JsonManipulator('{
  1881. "repositories": {
  1882. }
  1883. }');
  1884. $this->assertTrue($manipulator->addRepository('bar', array('type' => 'composer')));
  1885. $this->assertEquals('{
  1886. "repositories": {
  1887. "bar": {
  1888. "type": "composer"
  1889. }
  1890. }
  1891. }
  1892. ', $manipulator->getContents());
  1893. }
  1894. public function testAddRepositoryCanInitializeFromScratch()
  1895. {
  1896. $manipulator = new JsonManipulator("{
  1897. \t\"a\": \"b\"
  1898. }");
  1899. $this->assertTrue($manipulator->addRepository('bar2', array('type' => 'composer')));
  1900. $this->assertEquals("{
  1901. \t\"a\": \"b\",
  1902. \t\"repositories\": {
  1903. \t\t\"bar2\": {
  1904. \t\t\t\"type\": \"composer\"
  1905. \t\t}
  1906. \t}
  1907. }
  1908. ", $manipulator->getContents());
  1909. }
  1910. public function testAddRepositoryCanAdd()
  1911. {
  1912. $manipulator = new JsonManipulator('{
  1913. "repositories": {
  1914. "foo": {
  1915. "type": "vcs",
  1916. "url": "lala"
  1917. }
  1918. }
  1919. }');
  1920. $this->assertTrue($manipulator->addRepository('bar', array('type' => 'composer')));
  1921. $this->assertEquals('{
  1922. "repositories": {
  1923. "foo": {
  1924. "type": "vcs",
  1925. "url": "lala"
  1926. },
  1927. "bar": {
  1928. "type": "composer"
  1929. }
  1930. }
  1931. }
  1932. ', $manipulator->getContents());
  1933. }
  1934. public function testAddRepositoryCanOverrideDeepRepos()
  1935. {
  1936. $manipulator = new JsonManipulator('{
  1937. "repositories": {
  1938. "baz": {
  1939. "type": "package",
  1940. "package": {}
  1941. }
  1942. }
  1943. }');
  1944. $this->assertTrue($manipulator->addRepository('baz', array('type' => 'composer')));
  1945. $this->assertEquals('{
  1946. "repositories": {
  1947. "baz": {
  1948. "type": "composer"
  1949. }
  1950. }
  1951. }
  1952. ', $manipulator->getContents());
  1953. }
  1954. public function testAddConfigSettingEscapes()
  1955. {
  1956. $manipulator = new JsonManipulator('{
  1957. "config": {
  1958. }
  1959. }');
  1960. $this->assertTrue($manipulator->addConfigSetting('test', 'a\b'));
  1961. $this->assertTrue($manipulator->addConfigSetting('test2', "a\nb\fa"));
  1962. $this->assertEquals('{
  1963. "config": {
  1964. "test": "a\\\\b",
  1965. "test2": "a\nb\fa"
  1966. }
  1967. }
  1968. ', $manipulator->getContents());
  1969. }
  1970. public function testAddConfigSettingWorksFromScratch()
  1971. {
  1972. $manipulator = new JsonManipulator('{
  1973. }');
  1974. $this->assertTrue($manipulator->addConfigSetting('foo.bar', 'baz'));
  1975. $this->assertEquals('{
  1976. "config": {
  1977. "foo": {
  1978. "bar": "baz"
  1979. }
  1980. }
  1981. }
  1982. ', $manipulator->getContents());
  1983. }
  1984. public function testAddConfigSettingCanAdd()
  1985. {
  1986. $manipulator = new JsonManipulator('{
  1987. "config": {
  1988. "foo": "bar"
  1989. }
  1990. }');
  1991. $this->assertTrue($manipulator->addConfigSetting('bar', 'baz'));
  1992. $this->assertEquals('{
  1993. "config": {
  1994. "foo": "bar",
  1995. "bar": "baz"
  1996. }
  1997. }
  1998. ', $manipulator->getContents());
  1999. }
  2000. public function testAddConfigSettingCanOverwrite()
  2001. {
  2002. $manipulator = new JsonManipulator('{
  2003. "config": {
  2004. "foo": "bar",
  2005. "bar": "baz"
  2006. }
  2007. }');
  2008. $this->assertTrue($manipulator->addConfigSetting('foo', 'zomg'));
  2009. $this->assertEquals('{
  2010. "config": {
  2011. "foo": "zomg",
  2012. "bar": "baz"
  2013. }
  2014. }
  2015. ', $manipulator->getContents());
  2016. }
  2017. public function testAddConfigSettingCanOverwriteNumbers()
  2018. {
  2019. $manipulator = new JsonManipulator('{
  2020. "config": {
  2021. "foo": 500
  2022. }
  2023. }');
  2024. $this->assertTrue($manipulator->addConfigSetting('foo', 50));
  2025. $this->assertEquals('{
  2026. "config": {
  2027. "foo": 50
  2028. }
  2029. }
  2030. ', $manipulator->getContents());
  2031. }
  2032. public function testAddConfigSettingCanOverwriteArrays()
  2033. {
  2034. $manipulator = new JsonManipulator('{
  2035. "config": {
  2036. "github-oauth": {
  2037. "github.com": "foo"
  2038. },
  2039. "github-protocols": ["https"]
  2040. }
  2041. }');
  2042. $this->assertTrue($manipulator->addConfigSetting('github-protocols', array('https', 'http')));
  2043. $this->assertEquals('{
  2044. "config": {
  2045. "github-oauth": {
  2046. "github.com": "foo"
  2047. },
  2048. "github-protocols": ["https", "http"]
  2049. }
  2050. }
  2051. ', $manipulator->getContents());
  2052. $this->assertTrue($manipulator->addConfigSetting('github-oauth', array('github.com' => 'bar', 'alt.example.org' => 'baz')));
  2053. $this->assertEquals('{
  2054. "config": {
  2055. "github-oauth": {
  2056. "github.com": "bar",
  2057. "alt.example.org": "baz"
  2058. },
  2059. "github-protocols": ["https", "http"]
  2060. }
  2061. }
  2062. ', $manipulator->getContents());
  2063. }
  2064. public function testAddConfigSettingCanAddSubKeyInEmptyConfig()
  2065. {
  2066. $manipulator = new JsonManipulator('{
  2067. "config": {
  2068. }
  2069. }');
  2070. $this->assertTrue($manipulator->addConfigSetting('github-oauth.bar', 'baz'));
  2071. $this->assertEquals('{
  2072. "config": {
  2073. "github-oauth": {
  2074. "bar": "baz"
  2075. }
  2076. }
  2077. }
  2078. ', $manipulator->getContents());
  2079. }
  2080. public function testAddConfigSettingCanAddSubKeyInEmptyVal()
  2081. {
  2082. $manipulator = new JsonManipulator('{
  2083. "config": {
  2084. "github-oauth": {},
  2085. "github-oauth2": {
  2086. }
  2087. }
  2088. }');
  2089. $this->assertTrue($manipulator->addConfigSetting('github-oauth.bar', 'baz'));
  2090. $this->assertTrue($manipulator->addConfigSetting('github-oauth2.a.bar', 'baz2'));
  2091. $this->assertTrue($manipulator->addConfigSetting('github-oauth3.b', 'c'));
  2092. $this->assertEquals('{
  2093. "config": {
  2094. "github-oauth": {
  2095. "bar": "baz"
  2096. },
  2097. "github-oauth2": {
  2098. "a.bar": "baz2"
  2099. },
  2100. "github-oauth3": {
  2101. "b": "c"
  2102. }
  2103. }
  2104. }
  2105. ', $manipulator->getContents());
  2106. }
  2107. public function testAddConfigSettingCanAddSubKeyInHash()
  2108. {
  2109. $manipulator = new JsonManipulator('{
  2110. "config": {
  2111. "github-oauth": {
  2112. "github.com": "foo"
  2113. }
  2114. }
  2115. }');
  2116. $this->assertTrue($manipulator->addConfigSetting('github-oauth.bar', 'baz'));
  2117. $this->assertEquals('{
  2118. "config": {
  2119. "github-oauth": {
  2120. "github.com": "foo",
  2121. "bar": "baz"
  2122. }
  2123. }
  2124. }
  2125. ', $manipulator->getContents());
  2126. }
  2127. public function testAddRootSettingDoesNotBreakDots()
  2128. {
  2129. $manipulator = new JsonManipulator('{
  2130. "github-oauth": {
  2131. "github.com": "foo"
  2132. }
  2133. }');
  2134. $this->assertTrue($manipulator->addSubNode('github-oauth', 'bar', 'baz'));
  2135. $this->assertEquals('{
  2136. "github-oauth": {
  2137. "github.com": "foo",
  2138. "bar": "baz"
  2139. }
  2140. }
  2141. ', $manipulator->getContents());
  2142. }
  2143. public function testRemoveConfigSettingCanRemoveSubKeyInHash()
  2144. {
  2145. $manipulator = new JsonManipulator('{
  2146. "config": {
  2147. "github-oauth": {
  2148. "github.com": "foo",
  2149. "bar": "baz"
  2150. }
  2151. }
  2152. }');
  2153. $this->assertTrue($manipulator->removeConfigSetting('github-oauth.bar'));
  2154. $this->assertEquals('{
  2155. "config": {
  2156. "github-oauth": {
  2157. "github.com": "foo"
  2158. }
  2159. }
  2160. }
  2161. ', $manipulator->getContents());
  2162. }
  2163. public function testRemoveConfigSettingCanRemoveSubKeyInHashWithSiblings()
  2164. {
  2165. $manipulator = new JsonManipulator('{
  2166. "config": {
  2167. "foo": "bar",
  2168. "github-oauth": {
  2169. "github.com": "foo",
  2170. "bar": "baz"
  2171. }
  2172. }
  2173. }');
  2174. $this->assertTrue($manipulator->removeConfigSetting('github-oauth.bar'));
  2175. $this->assertEquals('{
  2176. "config": {
  2177. "foo": "bar",
  2178. "github-oauth": {
  2179. "github.com": "foo"
  2180. }
  2181. }
  2182. }
  2183. ', $manipulator->getContents());
  2184. }
  2185. public function testAddMainKey()
  2186. {
  2187. $manipulator = new JsonManipulator('{
  2188. "foo": "bar"
  2189. }');
  2190. $this->assertTrue($manipulator->addMainKey('bar', 'baz'));
  2191. $this->assertEquals('{
  2192. "foo": "bar",
  2193. "bar": "baz"
  2194. }
  2195. ', $manipulator->getContents());
  2196. }
  2197. public function testAddMainKeyWithContentHavingDollarSignFollowedByDigit()
  2198. {
  2199. $manipulator = new JsonManipulator('{
  2200. "foo": "bar"
  2201. }');
  2202. $this->assertTrue($manipulator->addMainKey('bar', '$1baz'));
  2203. $this->assertEquals('{
  2204. "foo": "bar",
  2205. "bar": "$1baz"
  2206. }
  2207. ', $manipulator->getContents());
  2208. }
  2209. public function testAddMainKeyWithContentHavingDollarSignFollowedByDigit2()
  2210. {
  2211. $manipulator = new JsonManipulator('{}');
  2212. $this->assertTrue($manipulator->addMainKey('foo', '$1bar'));
  2213. $this->assertEquals('{
  2214. "foo": "$1bar"
  2215. }
  2216. ', $manipulator->getContents());
  2217. }
  2218. public function testUpdateMainKey()
  2219. {
  2220. $manipulator = new JsonManipulator('{
  2221. "foo": "bar"
  2222. }');
  2223. $this->assertTrue($manipulator->addMainKey('foo', 'baz'));
  2224. $this->assertEquals('{
  2225. "foo": "baz"
  2226. }
  2227. ', $manipulator->getContents());
  2228. }
  2229. public function testUpdateMainKey2()
  2230. {
  2231. $manipulator = new JsonManipulator('{
  2232. "a": {
  2233. "foo": "bar",
  2234. "baz": "qux"
  2235. },
  2236. "foo": "bar",
  2237. "baz": "bar"
  2238. }');
  2239. $this->assertTrue($manipulator->addMainKey('foo', 'baz'));
  2240. $this->assertTrue($manipulator->addMainKey('baz', 'quux'));
  2241. $this->assertEquals('{
  2242. "a": {
  2243. "foo": "bar",
  2244. "baz": "qux"
  2245. },
  2246. "foo": "baz",
  2247. "baz": "quux"
  2248. }
  2249. ', $manipulator->getContents());
  2250. }
  2251. public function testUpdateMainKey3()
  2252. {
  2253. $manipulator = new JsonManipulator('{
  2254. "require": {
  2255. "php": "5.*"
  2256. },
  2257. "require-dev": {
  2258. "foo": "bar"
  2259. }
  2260. }');
  2261. $this->assertTrue($manipulator->addMainKey('require-dev', array('foo' => 'qux')));
  2262. $this->assertEquals('{
  2263. "require": {
  2264. "php": "5.*"
  2265. },
  2266. "require-dev": {
  2267. "foo": "qux"
  2268. }
  2269. }
  2270. ', $manipulator->getContents());
  2271. }
  2272. public function testUpdateMainKeyWithContentHavingDollarSignFollowedByDigit()
  2273. {
  2274. $manipulator = new JsonManipulator('{
  2275. "foo": "bar"
  2276. }');
  2277. $this->assertTrue($manipulator->addMainKey('foo', '$1bar'));
  2278. $this->assertEquals('{
  2279. "foo": "$1bar"
  2280. }
  2281. ', $manipulator->getContents());
  2282. }
  2283. public function testRemoveMainKey()
  2284. {
  2285. $manipulator = new JsonManipulator('{
  2286. "repositories": [
  2287. {
  2288. "package": {
  2289. "require": {
  2290. "this/should-not-end-up-in-root-require": "~2.0"
  2291. },
  2292. "require-dev": {
  2293. "this/should-not-end-up-in-root-require-dev": "~2.0"
  2294. }
  2295. }
  2296. }
  2297. ],
  2298. "require": {
  2299. "package/a": "*",
  2300. "package/b": "*",
  2301. "package/c": "*"
  2302. },
  2303. "foo": "bar",
  2304. "require-dev": {
  2305. "package/d": "*"
  2306. }
  2307. }');
  2308. $this->assertTrue($manipulator->removeMainKey('repositories'));
  2309. $this->assertEquals('{
  2310. "require": {
  2311. "package/a": "*",
  2312. "package/b": "*",
  2313. "package/c": "*"
  2314. },
  2315. "foo": "bar",
  2316. "require-dev": {
  2317. "package/d": "*"
  2318. }
  2319. }
  2320. ', $manipulator->getContents());
  2321. $this->assertTrue($manipulator->removeMainKey('foo'));
  2322. $this->assertEquals('{
  2323. "require": {
  2324. "package/a": "*",
  2325. "package/b": "*",
  2326. "package/c": "*"
  2327. },
  2328. "require-dev": {
  2329. "package/d": "*"
  2330. }
  2331. }
  2332. ', $manipulator->getContents());
  2333. $this->assertTrue($manipulator->removeMainKey('require'));
  2334. $this->assertTrue($manipulator->removeMainKey('require-dev'));
  2335. $this->assertEquals('{
  2336. }
  2337. ', $manipulator->getContents());
  2338. }
  2339. public function testRemoveMainKeyRemovesKeyWhereValueIsNull()
  2340. {
  2341. $manipulator = new JsonManipulator(json_encode(array(
  2342. 'foo' => 9000,
  2343. 'bar' => null,
  2344. )));
  2345. $manipulator->removeMainKey('bar');
  2346. $expected = json_encode(array(
  2347. 'foo' => 9000,
  2348. ));
  2349. $this->assertJsonStringEqualsJsonString($expected, $manipulator->getContents());
  2350. }
  2351. public function testIndentDetection()
  2352. {
  2353. $manipulator = new JsonManipulator('{
  2354. "require": {
  2355. "php": "5.*"
  2356. }
  2357. }');
  2358. $this->assertTrue($manipulator->addMainKey('require-dev', array('foo' => 'qux')));
  2359. $this->assertEquals('{
  2360. "require": {
  2361. "php": "5.*"
  2362. },
  2363. "require-dev": {
  2364. "foo": "qux"
  2365. }
  2366. }
  2367. ', $manipulator->getContents());
  2368. }
  2369. public function testRemoveMainKeyAtEndOfFile()
  2370. {
  2371. $manipulator = new JsonManipulator('{
  2372. "require": {
  2373. "package/a": "*"
  2374. }
  2375. }
  2376. ');
  2377. $this->assertTrue($manipulator->addMainKey('homepage', 'http...'));
  2378. $this->assertTrue($manipulator->addMainKey('license', 'mit'));
  2379. $this->assertEquals('{
  2380. "require": {
  2381. "package/a": "*"
  2382. },
  2383. "homepage": "http...",
  2384. "license": "mit"
  2385. }
  2386. ', $manipulator->getContents());
  2387. $this->assertTrue($manipulator->removeMainKey('homepage'));
  2388. $this->assertTrue($manipulator->removeMainKey('license'));
  2389. $this->assertEquals('{
  2390. "require": {
  2391. "package/a": "*"
  2392. }
  2393. }
  2394. ', $manipulator->getContents());
  2395. }
  2396. public function testEscapedUnicodeDoesNotCauseBacktrackLimitErrorGithubIssue8131()
  2397. {
  2398. $manipulator = new JsonManipulator('{
  2399. "description": "Some U\u00F1icode",
  2400. "require": {
  2401. "foo/bar": "^1.0"
  2402. }
  2403. }');
  2404. $this->assertTrue($manipulator->addLink('require', 'foo/baz', '^1.0'));
  2405. $this->assertEquals('{
  2406. "description": "Some U\u00F1icode",
  2407. "require": {
  2408. "foo/bar": "^1.0",
  2409. "foo/baz": "^1.0"
  2410. }
  2411. }
  2412. ', $manipulator->getContents());
  2413. }
  2414. }