{"id":13519716,"url":"https://github.com/atoum/netbeans-sample","last_synced_at":"2025-04-10T05:32:12.844Z","repository":{"id":8182725,"uuid":"9608762","full_name":"atoum/netbeans-sample","owner":"atoum","description":null,"archived":false,"fork":false,"pushed_at":"2014-09-18T21:01:12.000Z","size":716,"stargazers_count":3,"open_issues_count":0,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-24T16:46:07.718Z","etag":null,"topics":["atoum","atoum-starter","netbeans","netbeans-atoum","php","tutorial","xdebug"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atoum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-22T20:54:55.000Z","updated_at":"2018-03-03T20:04:50.000Z","dependencies_parsed_at":"2022-08-06T04:15:37.473Z","dependency_job_id":null,"html_url":"https://github.com/atoum/netbeans-sample","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atoum%2Fnetbeans-sample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atoum%2Fnetbeans-sample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atoum%2Fnetbeans-sample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atoum%2Fnetbeans-sample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atoum","download_url":"https://codeload.github.com/atoum/netbeans-sample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248163189,"owners_count":21057886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atoum","atoum-starter","netbeans","netbeans-atoum","php","tutorial","xdebug"],"created_at":"2024-08-01T05:02:02.289Z","updated_at":"2025-04-10T05:32:12.327Z","avatar_url":"https://github.com/atoum.png","language":"PHP","readme":"### Netbeans + atoum = love \u003c3\n\nHi all! If you are here today, it's because you know and probably use [Netbeans](https://netbeans.org/features/php/). But you probably don't know [atoum](http://atoum.org) yet. Too bad, you missed one of the most powerfull and pleasant to use unit testing framework for PHP. Today, atoum is directly integrated in Netbeans and I'm here to introduce this new feature.\n\nWe, the atoum team, have one main goal: to provide users a modern, simple and intuitive tool to write unit tests. Integrating atoum in an IDE is a step farther to ease the use of such a tool. In this blog post, I'll try to cover the main functionalities: we will bootstrap a new project using atoum, configure it to be able to trigger our tests and then, we'll see how to debug them. Do not worry, thanks to Tomas and all the Netbeans' team work, this will be easy and will only happen through the Netbeans' user interface.\n\n#### Bootstrapping\n\nOnce you have created your new Netbeans project, you will have to build a basic directory structure. Let's use something like this:\n\n```\n.\n├── src\n│   └── netbeans\n│       └── sample\n└── tests\n    └── units\n        └── netbeans\n            └── sample\n```\n\nWhat does this tell us ? We prepared our project to host a ```netbeans\\sample``` namespace where we will put our sources and a directory to host our tests. The last thing to do before writing the first line of code is to include atoum. atoum is available as a [PHAR archive](http://downloads.atoum.org/nightly/mageekguy.atoum.phar), a [composer package](https://packagist.org/packages/atoum/atoum), or [on Github](https://github.com/atoum/atoum). In the example I'll use [composer](http://getcomposer.org/) with the following content in the ```composer.json``` file:\n\n```\n{\n    \"name\": \"netbeans/sample\",\n    \"description\": \"Netbeans + atoum = love \u003c3\",\n    \"require-dev\": {\n        \"atoum/atoum\": \"dev-master\"\n    },\n    \"autoload\": {\n        \"psr-0\": {\n            \"netbeans\\\\sample\": \"src\"\n        }\n    }\n}\n```\n\nThis could be automatically generated with Netbeans but I won't cover this step in detail here as it's the matter of one click: right click on your project name and choose Composer and then Install. As soon as you have your dependencies installed, you will be ready to continue.\n\n#### Configuring\n\nThis is where we will start using Netbeans features. Let's start by opening the project properties window (right-click on the project name and select \"Properties\" then go to the \"Testing\" item in the left tree):\n\n![Project properties - Testing](resources/images/configuring-1.png \"Project properties - Testing\")\n\nNow, we have to tell Netbeans which directory will hold our tests (still in project's properties, go to the \"Sources\" item in the left tree):\n\n![Project properties - Testing](resources/images/configuring-2.png \"Project properties - Testing\")\n\nUse the \"Browse\" button next to the \"Test folder\" field and choose the ```tests``` directory. You can now save the settings and see that Neatbeans marks the ```tests``` as a special folder: \"Test Files\". This will let it automatically find your test files based on your source filenames.\n\nFor now, that's all you need to do to make Netbeans use atoum to run your tests. I told you atoum was a really simple tool: it's a self-contained tool and can run your test without any configuration! Netbeans takes full advantage of this and only asks you to choose your favorite tool by checking a single option! Of course, when you'll be more familiar with the tool, you'll be able to customize it more precisely.\n\nFor basic use cases, this should be sufficient and we can go to the next step: writing our first unit test because TDD is a good practice and atoum is oriented on this way of working (but you can also use it other way).\n\n#### Writing unit tests\n\nBefore we start writing tests, let me explain some points I skipped until now: when we prepared our workspace, we created a deep tree in the tests directory. This is something that is required by atoum: you have to use namespace to structure your sources and tests and the tests should live in a namespace matching ```tests\\units``` and your source namespace. In our example, our tests will live in the ```tests\\units\\netbeans\\sample``` namespace as our sources are in ```netbeans\\sample```. We also follow the PSR-0 convention so our directories match the namespaces to ease autoloading.\n\nSo let's go! We want to write a Calculator class which will provide some basic operations: add, multiply and divide. Let's create the file ```tests/units/netbeans/sample/Calculator.php```:\n\n```\n\u003c?php\nnamespace tests\\units\\netbeans\\sample;\n\nuse atoum;\n\nrequire __DIR__ . '/../../../../vendor/autoload.php';\n\nclass Calculator extends atoum {\n    public function testAdd() {\n        $this\n                -\u003eif($object = new \\netbeans\\sample\\Calculator())\n                -\u003ethen\n                    -\u003einteger($object-\u003eadd(1, 2))-\u003eisEqualTo(3)\n        ;\n    }\n}\n```\n\nWe now have our first unit test, so just launch it: click on its filename in the left tree and, as you prefer, use the CMD+F6 shortcut on Mac OS X or use the right-click menu and select \"Run\". Netbeans should display the result of the test run, saying that a test failed. Exactly what we expect: we tested a method which we don't have yet implemented (TDD FTW!):\n\n![Unit tests - Failure](resources/images/result-2.png \"Unit tests - Failure\")\n\nWhat we have to do now is create our tested class and write the ```add``` method to make our test pass. Ass I told you, atoum and Netbeans expect your project to be PSR-0 compliant so our class will lay in the ```src/netbeans/sample``` directory:\n\n```\n\u003c?php\nnamespace netbeans\\sample;\n\nclass Calculator {\n    public function add($a, $b) {\n        return $a + $b;\n    }\n}\n```\n\nUsing you prefered trigger, you can now rerun the unit test and see that everything is now green!\n\n![Unit tests - Success](resources/images/result-1.png \"Unit tests - Success\")\n\nThis is how netbeans will report the tests results : a shiny progress bar and a list of ran test cases. If you are curious, you will also be able to see the command used to run tests and the raw output produced by atoum which is provided in the [TAP format](http://podwiki.hexten.net/TAP/TAP.html?page=TAP \"TAP format\") (I bet you won't want to read this but it's still interesting to know how everything works under the hood):\n\n![Unit tests - TAP output](resources/images/output-1.png \"Unit tests - TAP output\")\n\nI won't cover the other test methods and let you discover them [here](https://github.com/jubianchi/atoum-sample). Using TDD, you will now be able to quickly write a test, run it, see it's failing, switch to your source file (ALT+CMD+T on Mac OS X), write some code to make the test pass, run it, see it's passing, switch to the test (again with ALT+CMD+T), write a failing test, … This is how we do!\n\nWe will now switch to a new example to discover another feature: using XDebug to debug our code.\n\n#### Debugging\n\nNetbeans and atoum allow you to easily debug your code using XDebug. This is really handy when dealing with complex classes and tests. To show you how everything works, I'll use a ```Sorter``` class which has one method to do a bubble sorting on an array.\n\nBut before we can use XDebug with atoum, we'll have to do a bit of configuration. Here is the configuration used for the example:\n\n```\nzend_extension=xdebug.so\n\nxdebug.idekey=\"netbeans-xdebug\"\nxdebug.remote_enable=1\nxdebug.remote_autostart=0\n```\n\nWhat we do here is tell XDebug which IDE key will be used during debug session and enable remote debugging. ```remote_autostart``` will prevent atoum's child processes to automatically trigger a new session (yes, atoum runs every test in a single isolated PHP process!). If you want to know more about how to configure XDebug for a Netbeans usage, check out this [documentation](http://wiki.netbeans.org/HowToConfigureXDebug \"Netbeans XDebug configuration\")\n\nWe are now ready to debug! To start your test in debug mode, you can chose between a keyboard shortcut (CMD+Shift+F5 on Mac OS X) or by right-clicking on the test file and choosing \"Debug\". But before triggering tests, you will have to put some breakpoint in your code so you can control the execution flow using debugger tools (Step over, step into, …).\n\n![XDebug - Session](resources/images/xdebug.gif \"XDebug - Session\")\n\nBeing able to run s step-by-step debugger in unit tests context will help you debug your code as you can make a specific behavior happen and track the execution in detail using the call stack and variables inspectors. \n\n![XDebug - Inspectors](resources/images/inspectors.png \"XDebug - Inspectors\")\n\nNothing really new compared to a conventional debugger session but still useful.\n\nI hope the blog post made a good introduction to atoum in Netbeans, and perhaps made you want to test it. Of course, you will find all the code related to this post [on Github](https://github.com/jubianchi/atoum-sample). Feel free to check it out, try it and enjoy using atoum in Netbeans!\n\nI wanted to thank everyone who worked on these awesome features, [Tomáš Myšík](https://twitter.com/tmysik) for his work on Netbeans but also the entire Netbeans team and all the contributors who helped us make this happen. Finally, if you want to know more about atoum or need help, feel free to join us on [IRC](irc://irc.freenode.net/##atoum) or have a look at the [documentation](http://docs.atoum.org).\n\n![Netbeans + atoum = love \u003c3](resources/images/love.png \"Netbeans + atoum = love \u003c3\")","funding_links":[],"categories":["PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatoum%2Fnetbeans-sample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatoum%2Fnetbeans-sample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatoum%2Fnetbeans-sample/lists"}