Newsgroup: it.comp.www.php
Titolo: phpunit e funzioni di wordpress

$ cat AbcTest.php
<?php
class AbcTest extends PHPUnit\Framework\TestCase {
 
     function testAbc() {
         $this->assertSame(
             'abc',
             sanitize_text_field('abc')
         );
     }
 
}
 
$ phpunit AbcTest.php
Error: Call to undefined function sanitize_text_field()
/tmp/tmp.38jeN8ydXK/AbcTest.php:10
 
Purtroppo ha ragione: sanitize_text_field() è una funzione di wordpress.
C'è quindi un modo per caricare almeno solo le funzioni (il core) di 
wordpress?

 wordpress?
 
Hai provato a dare un'occhiata sul sito ufficiale di WP [1]?
 
g4b0
 
[1] 
https://make.wordpress.org/core/handbook/testing/automated-testing/
 
phpunit/
 
 


È partita bene, ma poi...
 
$ npm install
loadDep:phantomjs-prebuil ▀ 
╢████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
 
 > phantomjs...@2.1.16 install 
/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/phantomjs-prebuilt
 > node install.js
 
sh: 1: node: not found
Word...@5.0.0 /mnt/storage-ntfs/pending/abc/wordpress-develop
└─┬ grunt-con...@1.0.0
   └── rim...@2.6.2
 
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or 
architecture: fsev...@1.2.4
npm WARN ajv-ke...@3.2.0 requires a peer of ajv@^6.0.0 but none was 
installed.
npm WARN Word...@5.0.0 license should be a valid SPDX license expression
npm ERR! Linux 4.4.0-134-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn
 
npm ERR! phantomjs...@2.1.16 install: `node install.js`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the phantomjs...@2.1.16 install script 'node 
install.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the 
phantomjs-prebuilt package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node install.js
npm ERR! You can get information on how to open an issue for this 
project with:
npm ERR!     npm bugs phantomjs-prebuilt
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls phantomjs-prebuilt
npm ERR! There is likely additional logging output above.
 
npm ERR! Please include the following file with any support request:
npm ERR!     /mnt/storage-ntfs/pending/abc/wordpress-develop/npm-debug.log
 
$ grunt build
/usr/bin/env: "node": File o directory non esistente
 
$ grunt watch
/usr/bin/env: "node": File o directory non esistente
 
$ ../vendor/bin/phpunit
PHP Fatal error:  Class PHPUnit_Util_Test may not inherit from final 
class (PHPUnit\Util\Test) in 
/mnt/storage-ntfs/pending/abc/wordpress-develop/tests/phpunit/includes/phpunit6-compat.php 
on line 18

Il 30/08/2018 17:12, alex ha scritto:
 
Bisognava installare node, ma ci sono altri problemi
 
$ sudo apt-get install nodejs-legacy
$ npm install
loadDep:phantomjs-prebuil ▀ 
╢████████████████████████████████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░╟
 
 > phantomjs...@2.1.16 install 
/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/phantomjs-prebuilt
 > node install.js
 
PhantomJS not found on PATH
Downloading 
https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2
 
Saving to /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Receiving...
   [=======================================-] 98%
Received 22866K total.
Extracting tar contents (via spawned process)
Removing 
/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder 
/tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1535642679150/phantomjs-2.1.1-linux-x86_64 
-> 
/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at 
/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
Word...@5.0.0 /mnt/storage-ntfs/pending/abc/wordpress-develop
├─┬ grunt-con...@1.0.0
│ └── rim...@2.6.2
├─┬ grunt-cont...@1.0.0
│ └─┬ jsh...@2.9.6
│   ├── pha...@4.0.12
│   └─┬ phantomjs...@2.1.16
│     ├── es6-p...@4.2.4
│     ├─┬ extra...@1.6.7
│     │ └─┬ ya...@2.4.1
│     │   └─┬ fd-s...@1.0.1
│     │     └── pe...@1.2.0
│     ├─┬ fs-e...@1.0.0
│     │ ├── json...@2.4.0
│     │ └── kl...@1.3.1
│     ├── ha...@2.2.0
│     ├── k...@0.7.0
│     ├── prog...@1.1.8
│     └─┬ request-...@2.0.1
│       └── throt...@1.0.0
└─┬ grunt-con...@1.3.0
   └─┬ grunt-lib...@1.1.0
     └── rim...@2.6.2
 
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or 
architecture: fsev...@1.2.4
npm WARN ajv-ke...@3.2.0 requires a peer of ajv@^6.0.0 but none was 
installed.
npm WARN Word...@5.0.0 license should be a valid SPDX license expression
 
$ grunt build
Loading "patch_wordpress.js" tasks...ERROR
 >> SyntaxError: Unexpected token {
Loading "sass.js" tasks...ERROR
 >> Error: ENOENT: no such file or directory, scandir 
'/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/node-sass/vendor'
 >> Cannot rename missing "patch_wordpress" task.
 
Running "clean:all" (clean) task
 >> 0 paths cleaned.
 
Running "webpack:dev" (webpack) task
[0] Hash: 02f86c336451f0e6581a 
 
Version: webpack 3.12.0 / grunt-webpack 3.1.2
Child
     Hash: 02f86c336451f0e6581a
     Time: 3892ms
                                            Asset     Size  Chunks 
       Chunk Names
              build/wp-includes/js/media-views.js   247 kB    0, 1 
[emitted]  build/wp-includes/js/media-views.js
          build/wp-includes/js/media-views.min.js   101 kB    1, 0 
[emitted]  build/wp-includes/js/media-views.min.js
               build/wp-includes/js/media-grid.js  27.9 kB    2, 3 
[emitted]  build/wp-includes/js/media-grid.js
           build/wp-includes/js/media-grid.min.js  13.7 kB    3, 2 
[emitted]  build/wp-includes/js/media-grid.min.js
         build/wp-includes/js/media-audiovideo.js  26.3 kB    4, 5 
[emitted]  build/wp-includes/js/media-audiovideo.js
     build/wp-includes/js/media-audiovideo.min.js  12.4 kB    5, 4 
[emitted]  build/wp-includes/js/media-audiovideo.min.js
             build/wp-includes/js/media-models.js  44.2 kB    6, 7 
[emitted]  build/wp-includes/js/media-models.js
         build/wp-includes/js/media-models.min.js  13.5 kB    7, 6 
[emitted]  build/wp-includes/js/media-models.min.js
        [0] multi ./src/js/_enqueues/wp/media/audiovideo.js 28 bytes {4} 
{5} [built]
        [1] ./src/js/_enqueues/wp/media/audiovideo.js 6.08 kB {4} {5} 
[built]
        [2] ./src/js/media/models/post-media.js 1.09 kB {4} {5} [built]
        [8] ./src/js/media/views/media-details.js 3.99 kB {4} {5} [built]
        [9] ./src/js/media/views/audio-details.js 850 bytes {4} {5} [built]
       [10] ./src/js/media/views/video-details.js 985 bytes {4} {5} [built]
       [11] multi ./src/js/_enqueues/wp/media/grid.js 28 bytes {2} {3} 
[built]
       [12] ./src/js/_enqueues/wp/media/grid.js 962 bytes {2} {3} [built]
       [13] ./src/js/media/controllers/edit-attachment-metadata.js 699 
bytes {2} {3} [built]
       [14] ./src/js/media/views/frame/manage.js 7.74 kB {2} {3} [built]
       [22] multi ./src/js/_enqueues/wp/media/models.js 28 bytes {6} {7} 
[built]
       [23] ./src/js/_enqueues/wp/media/models.js 6.8 kB {6} {7} [built]
       [29] multi ./src/js/_enqueues/wp/media/views.js 28 bytes {0} {1} 
[built]
       [30] ./src/js/_enqueues/wp/media/views.js 7.83 kB {0} {1} [built]
      [104] ./src/js/media/views/spinner.js 1.01 kB {0} {1} [built]
         + 90 hidden modules
 
Running "copy:files" (copy) task
Created 115 directories, copied 1246 files
 
Running "copy:wp-admin-css-compat-rtl" (copy) task
Copied 1 file
 
Running "copy:wp-admin-css-compat-min" (copy) task
Copied 2 files
 
Running "copy:version" (copy) task
Copied 1 file
 
Running "copy:npm-packages" (copy) task
Copied 11 files
 
Running "copy:vendor-js" (copy) task
Created 46 directories, copied 146 files
 
Running "copy:admin-js" (copy) task
Copied 50 files
 
Running "copy:includes-js" (copy) task
Copied 36 files
 
Running "file_append:default_options" (file_append) task
 
Running "cssmin:core" (cssmin) task
 >> 36 files created. 660.18 kB → 556.43 kB
Warning: Task "sass:colors" not found. Use --force to continue.
 
Aborted due to warnings.
 
$ grunt watch
Loading "patch_wordpress.js" tasks...ERROR
 >> SyntaxError: Unexpected token {
Loading "sass.js" tasks...ERROR
 >> Error: ENOENT: no such file or directory, scandir 
'/mnt/storage-ntfs/pending/abc/wordpress-develop/node_modules/node-sass/vendor'
 >> Cannot rename missing "patch_wordpress" task.
 
Running "watch" task
 
Running "clean:all" (clean) task
 >> 1701 paths cleaned.
 
Running "webpack:dev" (webpack) task
[0] Hash: 02f86c336451f0e6581a 
 
Version: webpack 3.12.0 / grunt-webpack 3.1.2
Child
     Hash: 02f86c336451f0e6581a
     Time: 3356ms
                                            Asset     Size  Chunks 
       Chunk Names
              build/wp-includes/js/media-views.js   247 kB    0, 1 
[emitted]  build/wp-includes/js/media-views.js
          build/wp-includes/js/media-views.min.js   101 kB    1, 0 
[emitted]  build/wp-includes/js/media-views.min.js
               build/wp-includes/js/media-grid.js  27.9 kB    2, 3 
[emitted]  build/wp-includes/js/media-grid.js
           build/wp-includes/js/media-grid.min.js  13.7 kB    3, 2 
[emitted]  build/wp-includes/js/media-grid.min.js
         build/wp-includes/js/media-audiovideo.js  26.3 kB    4, 5 
[emitted]  build/wp-includes/js/media-audiovideo.js
     build/wp-includes/js/media-audiovideo.min.js  12.4 kB    5, 4 
[emitted]  build/wp-includes/js/media-audiovideo.min.js
             build/wp-includes/js/media-models.js  44.2 kB    6, 7 
[emitted]  build/wp-includes/js/media-models.js
         build/wp-includes/js/media-models.min.js  13.5 kB    7, 6 
[emitted]  build/wp-includes/js/media-models.min.js
        [0] multi ./src/js/_enqueues/wp/media/audiovideo.js 28 bytes {4} 
{5} [built]
        [1] ./src/js/_enqueues/wp/media/audiovideo.js 6.08 kB {4} {5} 
[built]
        [2] ./src/js/media/models/post-media.js 1.09 kB {4} {5} [built]
        [8] ./src/js/media/views/media-details.js 3.99 kB {4} {5} [built]
        [9] ./src/js/media/views/audio-details.js 850 bytes {4} {5} [built]
       [10] ./src/js/media/views/video-details.js 985 bytes {4} {5} [built]
       [11] multi ./src/js/_enqueues/wp/media/grid.js 28 bytes {2} {3} 
[built]
       [12] ./src/js/_enqueues/wp/media/grid.js 962 bytes {2} {3} [built]
       [13] ./src/js/media/controllers/edit-attachment-metadata.js 699 
bytes {2} {3} [built]
       [14] ./src/js/media/views/frame/manage.js 7.74 kB {2} {3} [built]
       [22] multi ./src/js/_enqueues/wp/media/models.js 28 bytes {6} {7} 
[built]
       [23] ./src/js/_enqueues/wp/media/models.js 6.8 kB {6} {7} [built]
       [29] multi ./src/js/_enqueues/wp/media/views.js 28 bytes {0} {1} 
[built]
       [30] ./src/js/_enqueues/wp/media/views.js 7.83 kB {0} {1} [built]
      [104] ./src/js/media/views/spinner.js 1.01 kB {0} {1} [built]
         + 90 hidden modules
 
Running "copy:files" (copy) task
Created 115 directories, copied 1246 files
 
Running "copy:wp-admin-css-compat-rtl" (copy) task
Copied 1 file
 
Running "copy:wp-admin-css-compat-min" (copy) task
Copied 2 files
 
Running "copy:version" (copy) task
Copied 1 file
 
Running "copy:npm-packages" (copy) task
Copied 11 files
 
Running "copy:vendor-js" (copy) task
Created 46 directories, copied 146 files
 
Running "copy:admin-js" (copy) task
Copied 50 files
 
Running "copy:includes-js" (copy) task
Copied 36 files
 
Running "file_append:default_options" (file_append) task
 
Running "cssmin:core" (cssmin) task
 >> 36 files created. 660.18 kB → 556.43 kB
Warning: Task "sass:colors" not found. Use --force to continue.
 
Aborted due to warnings.
